<?php

/* $hodnotyy = array('IN', 'D', 'D0.5', 'LV', 'LV0.5', 'PN', 'DO', 'OT', 'OT0.5', 'MD', 'MOD', 'A');
  $hodnoty = array('IN', 'D', 'D0.5', 'LV', 'LV0.5', 'PN', 'DO', 'OT', 'OT0.5', 'MD', 'MOD', 'A');
  $hodnoty2 = array('P', 'D', 'DP', 'LV', 'LVP', 'PN', 'DO', 'OT', 'OTP', 'MD', 'MOD', 'A');
  $hodnoty3 = array('V práci', 'Dovolenka', 'Pol dňa - dovolenka', 'Lekárske vyšetrenie', 'Pol dňa - lekárske vyštrenie', 'PN', 'Deň voľna', 'Voľno za nadčas', 'Pol dňa - voľno za nadčas', 'Materská dovolenka', 'Manager on duty', 'Absencia');
  $farby = array('#fff', '#92bdf8', '#92bdf8', '#d5f892', '#d5f892', '#f8cc92', '#fcfbbe', '#f998ff', '#f998ff', '#c2faf0', '#fc2a39', 'red');
  $farbyTlac = array('#000', 'blue', 'blue', 'green', 'green', 'maroon', 'orange', 'purple', 'purple', 'navy', 'red', 'red');
 */

$hodnotyy = array('IN', 'D', 'LV', 'PN', 'DO', 'OT', 'MD', 'MOD', 'A', 'LD');
$hodnoty = array('IN', 'D', 'LV', 'PN', 'DO', 'OT', 'MD', 'MOD', 'A', 'LD');
$hodnoty2 = array('P', 'D', 'LV', 'PN', 'DO', 'OT', 'MD', 'MOD', 'A', 'LD');
$hodnoty3 = array('V práci', 'Dovolenka', 'Lekárske vyšetrenie', 'PN', 'Deň voľna', 'Voľno za nadčas', 'Materská dovolenka', 'Manager on duty', 'Absencia', 'Lekárske vyšetrenie - doprovod');
$farby = array('#fff', '#92bdf8', '#d5f892', '#f8cc92', '#fcfbbe', '#f998ff', '#c2faf0', '#fc2a39', 'red', '#d5f892');
$farbyTlac = array('#000', 'blue', 'green', 'maroon', 'orange', 'purple', 'navy', 'red', 'red', 'green');

function over_prihl() {
    if (!Empty($_SESSION['bmb_prihlas_id'])) {
        $ip = $_SERVER['REMOTE_ADDR'];
        $akt_datcas = Date("Y-m-d H:i:s");

        $prihl_s = "SELECT * FROM prihlasenie WHERE id = '" . $_SESSION['bmb_prihlas_id'] . "' AND uspesne = 1 AND ip = '" . $ip . "' ";
        $prihl_q = MySQL_Query($prihl_s);
        $prihl_n = MySQL_Num_Rows($prihl_q);
        if ($prihl_n == 1) {
            $prihl = MySQL_Fetch_Array($prihl_q);
            if ($prihl['datcas_do'] >= $akt_datcas) {
                // $datcas_do = Date("Y-m-d H:i:s", Time()+600);
                $datcas_do = Date("Y-m-d H:i:s", Time() + 1440);
                $prihl_u = "UPDATE prihlasenie SET datcas_do = '" . $datcas_do . "' WHERE id = '" . $_SESSION['bmb_prihlas_id'] . "' ";
                $prihl_q = MySQL_Query($prihl_u);
                global $user_id;
                $user_id = $prihl['uid'];
                global $zedko;
                $zedko = $prihl['zedko'];
                global $falkMode;
                $falkMode = falkensteinerMode($user_id);
                global $falkAdmin;
                $falkAdmin = falkensteinerAdmin($user_id);
                if ($zedko == 0)
                    $lang_s = "SELECT lang FROM user WHERE id = '" . $user_id . "' ";
                else
                    $lang_s = "SELECT lang FROM z WHERE id = '" . $user_id . "' ";
                $lang_q = MySQL_Query($lang_s);
                $lang = MySQL_Fetch_Array($lang_q);
                global $lang_id;
                $lang_id = $lang['lang'];
                $veduci_s = "SELECT veduci_oddelenia FROM z WHERE id = '" . $user_id . "' ";
                $veduci_q = MySQL_Query($veduci_s);
                $veduci = MySQL_Fetch_Array($veduci_q);
                global $veduci_oddelenia;
                if (isset($veduci['veduci_oddelenia']) && (falkensteinerMode($user_id, true))) {
                    $veduci_oddelenia = (($veduci['veduci_oddelenia']));
                } else {
                    $veduci_oddelenia = 0;
                }
            } else {
                Header("Location: index.php");
                exit();
            }
        } else {
            logout();
        }
    } else {
        Header("Location: index.php");
        exit();
    }
}

function logout() {
    $datcas_do = $datcas_do = Date("Y-m-d H:i:s", Time() - 1);
    $prihl_u = "UPDATE prihlasenie SET datcas_do = '" . $datcas_do . "' WHERE id = '" . $_SESSION['bmb_prihlas_id'] . "' ";
    $prihl_q = MySQL_Query($prihl_u);
    UnSet($_SESSION['bmb_prihlas_id']);
    unset($_SESSION['bmb_spolid']);
    Header("Location: index.php");
    exit();
}

function zobraz_zam($zobraz, $back) {
    if ($zobraz == 0 || $zobraz == 1 || $zobraz == 2 || $zobraz == 3) {
        $_SESSION['zobraz_zam'] = $zobraz;

        if ($back == 1)
            $loc = "home.php?akc=3";
        else
            $loc = "index.php";
    }
    else
        $loc = "index.php";
    Header("Location: $loc");
}

function meno_prihlaseneho() {
    global $user_id, $zedko;
    if ($zedko == 0)
        $nac_s = "SELECT meno,priezvisko,spolid,admin FROM user WHERE id = '" . $user_id . "' ";
    else
        $nac_s = "SELECT meno,priezvisko,spolid FROM z WHERE id = '" . $user_id . "' ";
    $nac_q = MySQL_Query($nac_s);
    $nac = MySQL_Fetch_Array($nac_q);
    $ret = "<b>" . $nac['meno'] . " " . $nac['priezvisko'] . "</b>";
    if ($nac['spolid'] > 0) {
        $nac2_s = "SELECT nazov FROM spolocnost WHERE id = '" . $nac['spolid'] . "' ";
        $nac2_q = MySQL_Query($nac2_s);
        $nac2 = MySQL_Fetch_Array($nac2_q);
        $ret .= ", " . $nac2['nazov'];
    } else {
        if ($nac['admin'] == 1)
            $ret .= ", BMB Leitner CS - admin";
        else
            $ret .= ", BMB Leitner CS";
    }
    return $ret;
}

function falkensteinerMode($id, $manazer = false) {
    if (!$manazer)
        $about_user_s = "SELECT spolid FROM user WHERE id = '" . $id . "' ";
    else
        $about_user_s = "SELECT spolid FROM z WHERE id = '" . $id . "' ";
    $about_user_q = MySQL_Query($about_user_s);
    $about_user = MySQL_Fetch_Array($about_user_q);
    $about_company_s = "SELECT falkensteinerMode FROM spolocnost WHERE id = '" . $about_user['spolid'] . "' ";
    $about_company_q = MySQL_Query($about_company_s);
    $about_company = MySQL_Fetch_Array($about_company_q);
    if (isset($about_company['falkensteinerMode']) && ($about_company['falkensteinerMode'] == 1)) {
        return true;
    } else {
        return false;
    }
}

function falkensteinerAdmin($id) {
    $about_user_s = "SELECT admin FROM user WHERE id = '" . $id . "' ";
    $about_user_q = MySQL_Query($about_user_s);
    $about_user = MySQL_Fetch_Array($about_user_q);
    if ($about_user['admin'] == 1) {
        return true;
    } else {
        return false;
    }
}

function menu() {
    global $user_id, $zedko, $falkMode, $veduci_oddelenia;
    $about_user_s = "SELECT * FROM user WHERE id = '" . $user_id . "' ";
    $about_user_q = MySQL_Query($about_user_s);
    $about_user = MySQL_Fetch_Array($about_user_q);
    echo "<table align=\"left\" class=\"menu_oddel\"><tr><td rowspan=\"2\" valign=\"middle\">";
    echo "<a href=\"home.php\"><img src=\"images/logo.jpg\" border=\"0\" alt=\"\" /></a>";
    echo "</td><td class=\"menu\"> | ";
    if ($zedko == 0) {
        if ($about_user['spolid'] == 0) {
            if ($about_user['admin'] == 1) {
                echo "<a href=\"home.php?akc=1\" class=\"a_menu\">Spoločnosti</a> | <a href=\"home.php?akc=1&akc2=4\" class=\"a_menu\">Prispievatelia</a> | <a href=\"home.php?akc=2\" class=\"a_menu\">Zamestnanci BMB</a> | <a href=\"home.php?akc=6\" class=\"a_menu\">Dokumenty</a> | <a href=\"home.php?akc=44\" class=\"a_menu\">Blokovaní používatelia</a> | <a href=\"home.php?akc=8\" class=\"a_menu\">Kalendár</a> | <a href=\"home.php?akc=5\" class=\"a_menu\">Sviatky</a> | <a href=\"home.php?akc=13\" class=\"a_menu\">Jazyky</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">Heslo</a>";
            } else {
                echo "<a href=\"home.php?akc=10\" class=\"a_menu\">Zamestnanci</a> | <a href=\"home.php?akc=45\" class=\"a_menu\">Blokovaní používatelia</a> | <a href=\"home.php?akc=91\" class=\"a_menu\">Prehľadové tabuľky</a> | <a href=\"home.php?akc=12\" class=\"a_menu\">Dochádzka</a> | <a href=\"home.php?akc=11\" class=\"a_menu\">Dokumenty</a> | <a href=\"home.php?akc=15\" class=\"a_menu\">Výplatné pásky</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">Heslo</a>";
            }
        } else {
            if ($falkMode) {
                if ($about_user['admin'] == 1) {
                    echo "<a href=\"home.php?akc=3\" class=\"a_menu\">" . preklad(1) . "</a> | <a href=\"home.php?akc=78\" class=\"a_menu\">" . preklad(152) . "</a> | <a href=\"home.php?akc=4\" class=\"a_menu\">" . preklad(2) . "</a> | <a href=\"home.php?akc=77\" class=\"a_menu\">" . preklad(147) . "</a> | <a href=\"home.php?akc=91\" class=\"a_menu\">Prehľadové tabuľky</a> | <a href=\"home.php?akc=7\" class=\"a_menu\">" . preklad(3) . "</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">" . preklad(4) . "</a> | <a href=\"?ch_lang=1&lang=0\"><img src=\"images/sk.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=1\"><img src=\"images/en.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=2\"><img src=\"images/de.jpg\" style=\"border: 0px;\" /></a>";
                } else {
                    echo "<a href=\"home.php?akc=3\" class=\"a_menu\">" . preklad(1) . "</a> | <a href=\"home.php?akc=4\" class=\"a_menu\">" . preklad(2) . "</a> | <a href=\"home.php?akc=7\" class=\"a_menu\">" . preklad(3) . "</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">" . preklad(4) . "</a> | <a href=\"?ch_lang=1&lang=0\"><img src=\"images/sk.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=1\"><img src=\"images/en.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=2\"><img src=\"images/de.jpg\" style=\"border: 0px;\" /></a>";
                }
            } else {
                echo "<a href=\"home.php?akc=3\" class=\"a_menu\">" . preklad(1) . "</a> | <a href=\"home.php?akc=4\" class=\"a_menu\">" . preklad(2) . "</a> | <a href=\"home.php?akc=7\" class=\"a_menu\">" . preklad(3) . "</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">" . preklad(4) . "</a> | <a href=\"?ch_lang=1&lang=0\"><img src=\"images/sk.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=1\"><img src=\"images/en.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=2\"><img src=\"images/de.jpg\" style=\"border: 0px;\" /></a>";
            }
        }
    } else {
        if (($veduci_oddelenia)) {
            echo "<a href=\"home.php?akc=3\" class=\"a_menu\">" . preklad(1) . "</a> | <a href=\"home.php?akc=4\" class=\"a_menu\">" . preklad(2) . "</a> | <a href=\"home.php?akc=7\" class=\"a_menu\">" . preklad(3) . "</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">" . preklad(4) . "</a> | <a href=\"?ch_lang=1&lang=0\"><img src=\"images/sk.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=1\"><img src=\"images/en.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=2\"><img src=\"images/de.jpg\" style=\"border: 0px;\" /></a>";
        } else {
            echo "<a href=\"home.php?akc=14\" class=\"a_menu\">" . preklad(3) . "</a> | <a href=\"home.php?akc=16\" class=\"a_menu\">" . preklad(131) . "</a> | <a href=\"home.php?akc=9\" class=\"a_menu\">" . preklad(4) . "</a> | <a href=\"?ch_lang=1&lang=0\"><img src=\"images/sk.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=1\"><img src=\"images/en.jpg\" style=\"border: 0px;\" /></a> <a href=\"?ch_lang=1&lang=2\"><img src=\"images/de.jpg\" style=\"border: 0px;\" /></a>";
        }
    }
    echo "</td></tr><tr><td class=\"menu\">";
    echo " | <span style=\"font-weight: normal;\">" . preklad(5) . " " . meno_prihlaseneho() . "</span> | <a href=\"home.php?logout=1\" class=\"a_menu\">" . preklad(6) . "</a>";
    echo "</td></tr></table>\n";
}

function pristup($kto) {
    global $user_id, $zedko;
    $about_user_s = "SELECT * FROM user WHERE id = '" . $user_id . "' ";
    $about_user_q = MySQL_Query($about_user_s);
    $about_user = MySQL_Fetch_Array($about_user_q);

    $no_access = "no access";

    if ($kto == "admin") {
        if (!($about_user['spolid'] == 0 && $about_user['admin'] == 1) && $zedko == 0) {
            //Header ("Location: index.php");
            //echo $no_access;
            exit();
        }
    } elseif ($kto == "zamestnanec") {
        if (!($about_user['spolid'] == 0 && $about_user['admin'] == 0) && $zedko == 0) {
            //Header ("Location: index.php");
            //echo $no_access;
            exit();
        }
    } elseif ($kto == "user") {
        if (!($about_user['spolid'] != 0) && $zedko == 0) {
            //Header ("Location: index.php");
            //echo $no_access;
            exit();
        }
    } elseif ($kto == "zamx") {
        if ($zedko != 1) {
            //Header ("Location: index.php");
            //echo $no_access;
            exit();
        }
    }
}

function pristup_zid($zid) {
    global $user_id, $veduci_oddelenia;
    if ($veduci_oddelenia == 0)
        $over1_s = "SELECT spolid FROM user WHERE id = '" . $user_id . "' ";
    else
        $over1_s = "SELECT spolid,veduci_oddelenia FROM z WHERE id = '" . $user_id . "' ";
    $over1_q = MySQL_Query($over1_s);
    $over1 = MySQL_Fetch_Array($over1_q);

    $over2_s = "SELECT spolid,patri_k FROM z WHERE id = '" . $zid . "' ";
    $over2_q = MySQL_Query($over2_s);
    $over2 = MySQL_Fetch_Array($over2_q);
    if ($veduci_oddelenia == 0) {
        if ($over1['spolid'] == $over2['spolid'])
            $ret = 1;
        else
            $ret = 0;
    } else {
        if (($over1['spolid'] == $over2['spolid']) && ($over1['veduci_oddelenia'] == $over2['patri_k']))
            $ret = 1;
        else
            $ret = 0;
    }
    return $ret;
}

function date_conv_to_view($datum) {
    $cast = Explode(" ", $datum);
    $casti = Explode("-", $cast[0]);
    $ret = $casti[2] . "." . $casti[1] . "." . $casti[0];
    return $ret;
}

function date_conv_to_db($datum) {
    if (StrLen($datum) >= 8 && StrLen($datum) <= 10) {
        $casti = Explode(".", $datum);
        if (Count($casti) == 3) {
            if (StrLen($casti[2]) == 4) {
                if (StrLen($casti[1]) == 1 || StrLen($casti[1]) == 2) {
                    if (StrLen($casti[1]) == 1)
                        $casti[1] = "0" . $casti[1];
                    if (StrLen($casti[0]) == 1 || StrLen($casti[0]) == 2) {
                        if (StrLen($casti[0]) == 1)
                            $casti[0] = "0" . $casti[0];
                        $ret = $casti[2] . "-" . $casti[1] . "-" . $casti[0];
                    }
                    else {
                        $ret = "";
                    }
                } else {
                    $ret = "";
                }
            } else {
                $ret = "";
            }
        } else {
            $ret = "";
        }
    } else {
        $ret = "";
    }
    return $ret;
}

function zalamovanie_do_db($old_text) {
    $new_text = Str_Replace("<br />", "\n", $old_text);
    return $new_text;
}

function zalamovanie_na_vypis($old_text) {
    $new_text = Str_Replace("\n", "<br />", $old_text);
    return $new_text;
}

function mesiac_sk($mes) {
    $mesiac[1] = "Január";
    $mesiac[2] = "Február";
    $mesiac[3] = "Marec";
    $mesiac[4] = "Apríl";
    $mesiac[5] = "Máj";
    $mesiac[6] = "Jún";
    $mesiac[7] = "Júl";
    $mesiac[8] = "August";
    $mesiac[9] = "September";
    $mesiac[10] = "Október";
    $mesiac[11] = "November";
    $mesiac[12] = "December";

    return $mesiac[$mes];
}

function starost_user($uid) {
    $starost_s = "SELECT id,nazov FROM spolocnost WHERE uid = '" . $uid . "' ORDER BY nazov ASC";
    $starost_q = MySQL_Query($starost_s);
    $starost_n = MySQL_Num_Rows($starost_q);
    $j = 1;
    while ($starost = MySQL_Fetch_Array($starost_q)) {
        $ret .= "<a href=\"home.php?akc=1&spolid=" . $starost['id'] . "\">" . $starost['nazov'] . "</a>";
        if ($j < $starost_n)
            $ret .= "<br />";
        $j++;
    }
    if ($starost_n == 0)
        $ret = "&nbsp;";
    return $ret;
}

function starost_spol($spolid) {
    $starost_s = "SELECT user.id,user.meno,user.priezvisko FROM user,spolocnost WHERE spolocnost.id = '" . $spolid . "' AND user.id = spolocnost.uid";
    $starost_q = MySQL_Query($starost_s);
    $starost = MySQL_Fetch_Array($starost_q);
    if (Empty($starost['id']))
        $ret = "&nbsp;";
    else
        $ret = "<a href=\"home.php?akc=2&zid=" . $starost['id'] . "\">" . $starost['priezvisko'] . " " . $starost['meno'] . "</a>";
    return $ret;
}

function zoznam_spolocnosti() {
    $ord = Array("spolocnost.nazov", "user.priezvisko");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }

    echo "<h2>Spoločnosti</h2>\n";
    echo "<a href=\"home.php?akc=1&akc2=1\">* pridať spoločnosť</a><br />\n";
    echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
    echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=1&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Názov:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>&nbsp;</td><td><a href=\"?akc=1&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Zodpovedná osoba v BMB:</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>Počet prispievateľov:</td></tr>\n";
    $spol_s = "SELECT spolocnost.id,spolocnost.nazov,spolocnost.uid,user.meno,user.priezvisko FROM spolocnost,user WHERE user.id = spolocnost.uid ORDER BY " . $order_ok . " " . $asc_ok;
    $spol_q = MySQL_Query($spol_s);
    $i = 1;
    while ($spol = MySQL_Fetch_Array($spol_q)) {
        echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td><a href=\"?akc=1&spolid=" . $spol['id'] . "\">" . $spol['nazov'] . "</a></td><td><a href=\"?akc=1&akc2=1&spolid=" . $spol['id'] . "\">upraviť</a></td><td><a href=\"home.php?akc=2&zid=" . $spol['uid'] . "\">" . $spol['priezvisko'] . " " . $spol['meno'] . "</a></td><td align=\"right\">" . pocet_prispievatelov($spol['id']) . " - <a href=\"home.php?akc=1&akc2=2&spolid=" . $spol['id'] . "\">zobraziť</a></td></tr>\n";
        $i++;
    }
    echo "</table>";
}

function zoznam_zamestnancov_bmb() {
    $ord = Array("priezvisko");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }

    echo "<h2>Zamestnanci BMB</h2>\n";
    echo "<a href=\"home.php?akc=2&akc2=1\">* pridať zamestnanca</a><br />\n";
    echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
    echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=2&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Meno:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>Pridelené spoločnosti:</td><td>&nbsp;</td></tr>\n";
    $zam_s = "SELECT * FROM user WHERE spolid = 0 AND admin = 0 ORDER BY " . $order_ok . " " . $asc_ok;
    $zam_q = MySQL_Query($zam_s);
    $i = 1;
    while ($zam = MySQL_Fetch_Array($zam_q)) {
        echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td><a href=\"?akc=2&zid=" . $zam['id'] . "\">" . $zam['priezvisko'] . " " . $zam['meno'] . "</a></td><td>" . starost_user($zam['id']) . "</td><td><a href=\"?akc=2&akc2=1&zid=" . $zam['id'] . "\">upraviť</a></td></tr>\n";
        $i++;
    }
    echo "</table>";
}

function check_js($over_toto) {
    $ret = "<script language=\"JavaScript\" type=\"text/javascript\">\n";
    $ret .= "function check()\n{\n";

    $pocet = Count($over_toto);
    for ($i = 0; $i < $pocet; $i++) {
        $over = Explode(",", $over_toto[$i]);
        $ret .= "if (document.formular." . $over[0] . ".value == \"\")\n{\n alert('Vyplňte " . $over[1] . ".');\n document.formular." . $over[0] . ".focus();\n return false;\n}\n";
    }

    $ret .= "return true;\n}\n";
    $ret .= "</script>\n";
    echo $ret;
}

function pridat_zamestnanca_bmb($ak_edit) {
    if ($ak_edit > 0) {
        $over_s = "SELECT * FROM user WHERE id = '" . $ak_edit . "' AND spolid = 0 AND admin = 0";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n == 1)
            $over = MySQL_Fetch_Array($over_q);
        else
            $ak_edit = 0;
    }

    if ($ak_edit > 0)
        echo "<h2>Upraviť zamestnanca BMB</h2>\n";
    else
        echo "<h2>Pridať zamestnanca BMB</h2>\n";

    global $vypis;
    if (!Empty($vypis))
        echo $vypis . "<br />\n";

    $over_toto[] = "meno,Meno";
    $over_toto[] = "priezvisko,Priezvisko";
    $over_toto[] = "mail,E-mail";
    if ($ak_edit == 0) {
        $over_toto[] = "heslo,Heslo";
        $over_toto[] = "heslo2,Heslo-overenie";
    }

    check_js($over_toto);

    global $meno_ok;
    global $priezvisko_ok;
    global $mail_ok;
    global $tel_ok;
    global $ip_ok;

    echo "<form action=\"home.php?akc=2&akc2=1&zid=" . $ak_edit . "\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\" onsubmit=\"return check();\">\n";
    echo "<table>\n";
    echo "<tr><td><b>Meno:</b></td><td><input type=\"text\" name=\"meno\" value=\"" . (($_POST['meno']) ? $meno_ok : $over['meno']) . "\"></td></tr>\n";
    echo "<tr><td><b>Priezvisko:</b></td><td><input type=\"text\" name=\"priezvisko\" value=\"" . (($_POST['priezvisko']) ? $priezvisko_ok : $over['priezvisko']) . "\"></td></tr>\n";
    echo "<tr><td><b>E-mail:</b></td><td><input type=\"text\" name=\"mail\" value=\"" . (($_POST['mail']) ? $mail_ok : $over['mail']) . "\"></td></tr>\n";
    echo "<tr><td>" . (($ak_edit > 0) ? "" : "<b>") . "Heslo:" . (($ak_edit > 0) ? "" : "</b>") . "</td><td><input type=\"password\" name=\"heslo\" value=\"\"></td></tr>\n";
    echo "<tr><td>" . (($ak_edit > 0) ? "" : "<b>") . "Heslo-overenie:" . (($ak_edit > 0) ? "" : "</b>") . "</td><td><input type=\"password\" name=\"heslo2\" value=\"\"></td></tr>\n";
    if ($ak_edit > 0)
        echo "<tr><td colspan=\"2\">Ak chcete tomuto zamestnancovi zmeniť heslo, zadajte do oboch kolóniek nové heslo. Ak nie, nechajte obe prázdne.</td></tr>\n";
    echo "<tr><td>Telefón:</td><td><input type=\"text\" name=\"tel\" value=\"" . (($_POST['meno']) ? $tel_ok : $over['tel']) . "\"></td></tr>\n";
    echo "<tr><td>IP adresa:</td><td><input type=\"text\" name=\"ip\" value=\"" . (($_POST['meno']) ? $ip_ok : $over['ip']) . "\"></td></tr>\n";
    echo "<tr><td colspan=\"2\">Ak vyplníte IP adresu, tak tento zamestnanec sa bude môcť prihlásiť len z nej.<br />Ak chcete zadať viac adries, oddelte ich čiarkou. Ak necháte prázdne, tak sa môže prihlásiť odkialkoľvek.</td></tr>\n";
    echo "<tr><td>Fotografia:</td><td><input type=\"file\" name=\"foto\" /></td></tr>\n";
    echo "<tr><td colspan=\"2\">Fotografia môže mať maximálne rozmery 150 x 240 px a musí byť vo formáte JPG.</td></tr>\n";
    if ($ak_edit > 0) {
        $pic_s = "SELECT * FROM foto WHERE uid = '" . $ak_edit . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $pic_q = MySQL_Query($pic_s);
        $pic_n = MySQL_Num_Rows($pic_q);
        if ($pic_n == 1) {
            $pic = MySQL_Fetch_Array($pic_q);
            echo "<tr><td valign=\"middle\">Aktuálna fotografia:</td><td valign=\"middle\"><img src=\"foto/" . $pic['ftp'] . "\" alt=\"\" /> <a href=\"?akc=2&akc2=2&zid=" . $ak_edit . "\">vymazať</a></td></tr>\n";
        }
    }
    echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_zam_bmb\" value=\"1\"><input type=\"submit\" value=\"Uložiť\"></td></tr>\n";
    echo "</table>\n";
    echo "</form>";
}

function pridat_zamestnanca_bmb_uloz($ak_edit) {
    if (!Empty($_POST['meno']) && !Empty($_POST['priezvisko']) && !Empty($_POST['mail'])) {
        global $vypis;

        global $meno_ok;
        $meno_ok = Trim(HtmlSpecialChars($_POST['meno'], ENT_QUOTES));
        global $priezvisko_ok;
        $priezvisko_ok = Trim(HtmlSpecialChars($_POST['priezvisko'], ENT_QUOTES));
        global $mail_ok;
        $mail_ok = Trim(HtmlSpecialChars($_POST['mail'], ENT_QUOTES));
        if (!Empty($_POST['heslo']))
            $heslo_ok = Trim(MD5($_POST['heslo']));
        else
            $heslo_ok = "";
        global $tel_ok;
        $tel_ok = Trim(HtmlSpecialChars($_POST['tel'], ENT_QUOTES));
        global $ip_ok;
        $ip_ok = Trim(HtmlSpecialChars($_POST['ip'], ENT_QUOTES));

        if ($ak_edit > 0) {
            $over_s = "SELECT * FROM user WHERE id = '" . $ak_edit . "' AND spolid = 0 AND admin = 0";
            $over_q = MySQL_Query($over_s);
            $over_n = MySQL_Num_Rows($over_q);
            if ($over_n == 1)
                $over = MySQL_Fetch_Array($over_q);
            else
                $ak_edit = 0;
        }

        if (($ak_edit == 0 && !Empty($_POST['heslo']) && !Empty($_POST['heslo2'])) || ($ak_edit > 0)) {
            if ($_POST['heslo'] == $_POST['heslo2']) {
                if (Eregi("^[_a-zA-Z0-9]+([-\.][_a-zA-Z0-9]+)*@[_a-zA-Z0-9]+([-\.][_a-zA-Z0-9]+)*\.[_a-zA-Z0-9]{2,4}$", $mail_ok)) {
                    $over_mail_s = "SELECT id FROM user WHERE mail = '" . $mail_ok . "' ";
                    $over_mail_q = MySQL_Query($over_mail_s);
                    $over_mail_n = MySQL_Num_Rows($over_mail_q);
                    $over_mail2_s = "SELECT id FROM z WHERE mail = '" . $mail_ok . "' ";
                    $over_mail2_q = MySQL_Query($over_mail2_s);
                    $over_mail2_n = MySQL_Num_Rows($over_mail2_q);
                    if ($over_mail_n == 0 || $over_mail2_n == 0 || $ak_edit > 0) {
                        if (!Empty($meno_ok) && !Empty($priezvisko_ok) && !Empty($mail_ok)) {
                            if ($ak_edit == 0) {
                                $uloz_i = "INSERT INTO user (id, spolid, meno, priezvisko, mail, heslo, tel, admin, ip, notifikacia, active, lang) VALUES (NULL, 0, '" . $meno_ok . "', '" . $priezvisko_ok . "', '" . $mail_ok . "', '" . $heslo_ok . "', '" . $tel_ok . "', 0, '" . $ip_ok . "', 1, 1, 0)";
                                $uloz_q = MySQL_Query($uloz_i);
                                $zid = MySQL_Insert_ID();
                            } else {
                                $uloz_u = "UPDATE user SET meno = '" . $meno_ok . "', priezvisko = '" . $priezvisko_ok . "', mail = '" . $mail_ok . "'";
                                if (!Empty($heslo_ok))
                                    $uloz_u .= ", heslo = '" . $heslo_ok . "'";
                                $uloz_u .= ", tel = '" . $tel_ok . "', ip = '" . $ip_ok . "' WHERE id = '" . $ak_edit . "' ";
                                $uloz_q = MySQL_Query($uloz_u);
                                $zid = $ak_edit;
                            }
                            $pictmp = $_FILES["foto"]["tmp_name"];
                            if (Is_Uploaded_File($pictmp)) {
                                $pictyp = ($_FILES["foto"]["type"]);
                                if (($pictyp == 'image/jpeg') || ($pictyp == 'image/pjpeg')) {
                                    $akt_cas = Time();
                                    $name = "foto_" . $zid . "_" . $akt_cas . ".jpg";
                                    @mkdir($pictmp, 0777);
                                    @chmod($pictmp, 0777);
                                    if (Move_Uploaded_File($pictmp, "foto/$name")) {
                                        $zmaz_u = "UPDATE foto SET active = 0 WHERE uid = '" . $zid . "' ";
                                        $zmaz_q = MySQL_Query($zmaz_u);
                                        $pridaj_i = "INSERT INTO foto (id, uid, ftp, active) VALUES (NULL, '" . $zid . "', '" . $name . "', 1)";
                                        $pridaj_q = MySQL_Query($pridaj_i);
                                    }
                                }
                            }
                            Header("Location: home.php?akc=2");
                            exit();
                        } else {
                            $vypis = "Povinné údaje musia byť vyplnené!";
                        }
                    } else {
                        $vypis = "Zadaný e-mail už je použitý!";
                    }
                } else {
                    $vypis = "Zadaný e-mail nie je v správnom tvare!";
                }
            } else {
                $vypis = "Zadané heslá nie sú rovnaké!";
            }
        } else {
            $vypis = "Heslo musí byť vyplnené!";
        }
    }
}

function vymazat_foto_zamestnanca_bmb($zid) {
    $zmaz_u = "UPDATE foto SET active = 0 WHERE uid = '" . $zid . "' ";
    $zmaz_q = MySQL_Query($zmaz_u);
    Header("Location: ?akc=2&akc2=1&zid=" . $zid);
    exit();
}

function profil_zamestnanec_bmb($zid) {
    echo "<h2>Zamestnanec BMB</h2>\n";
    $over_s = "SELECT * FROM user WHERE id = '" . $zid . "' AND spolid = 0 AND admin = 0";
    $over_q = MySQL_Query($over_s);
    $over_n = MySQL_Num_Rows($over_q);
    if ($over_n == 1) {
        $over = MySQL_Fetch_Array($over_q);
        echo "<table>\n";
        echo "<tr><td>Meno:</td><td>" . $over['meno'] . " " . $over['priezvisko'] . "</td></tr>\n";
        echo "<tr><td>E-mail:</td><td>" . $over['mail'] . "</td></tr>\n";
        echo "<tr><td>Telefón:</td><td>" . $over['tel'] . "</td></tr>\n";
        echo "<tr><td>IP adresa:</td><td>" . $over['ip'] . "</td></tr>\n";
        echo "<tr><td>Pridelené spoločnosti:</td><td>" . starost_user($zid) . "</td></tr>\n";
        echo "</table>\n";
    } else {
        echo "Takýto zamestnanec BMB neexistuje.";
    }
}

function pridat_spolocnost($ak_edit) {
    if ($ak_edit > 0) {
        $over_s = "SELECT * FROM spolocnost WHERE id = '" . $ak_edit . "' ";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n == 1)
            $over = MySQL_Fetch_Array($over_q);
        else
            $ak_edit = 0;
    }

    if ($ak_edit > 0)
        echo "<h2>Upraviť spoločnosť</h2>\n";
    else
        echo "<h2>Pridať spoločnosť</h2>\n";

    global $vypis;
    if (!Empty($vypis))
        echo $vypis . "<br />\n";

    $over_toto[] = "nazov,Názov";
    $over_toto[] = "ulica,Ulicu";
    $over_toto[] = "psc,PSČ";
    $over_toto[] = "mesto,Mesto";
    $over_toto[] = "starost,Zodpovednú osobu v BMB";

    check_js($over_toto);

    global $nazov_ok;
    global $ulica_ok;
    global $psc_ok;
    global $mesto_ok;
    global $starost_ok;

    echo "<form action=\"home.php?akc=1&akc2=1&spolid=" . $ak_edit . "\" method=\"post\" name=\"formular\" onsubmit=\"return check();\">\n";
    echo "<table>\n";
    echo "<tr><td><b>Názov:</b></td><td><input type=\"text\" name=\"nazov\" value=\"" . (($_POST['nazov']) ? $nazov_ok : $over['nazov']) . "\"></td></tr>\n";
    echo "<tr><td><b>Ulica:</b></td><td><input type=\"text\" name=\"ulica\" value=\"" . (($_POST['ulica']) ? $ulica_ok : $over['ulica']) . "\"></td></tr>\n";
    echo "<tr><td><b>PSČ:</b></td><td><input type=\"text\" name=\"psc\" value=\"" . (($_POST['psc']) ? $psc_ok : $over['psc']) . "\"></td></tr>\n";
    echo "<tr><td><b>Mesto:</b></td><td><input type=\"text\" name=\"mesto\" value=\"" . (($_POST['mesto']) ? $mesto_ok : $over['mesto']) . "\"></td></tr>\n";
    echo "<tr><td><b>Typ dochádzky:</b></td><td><select name=\"typ_dochadzky\">";
    $typy_s = "SELECT * FROM dochadzka_typ ORDER BY id ASC";
    $typy_q = MySQL_Query($typy_s);
    while ($typy = MySQL_Fetch_Array($typy_q)) {
        echo "<option value=\"" . $typy['id'] . "\"" . (($over['dtid'] == $typy['id']) ? " selected" : "") . ">" . $typy['typ'] . "</option>";
    }
    echo "</select></td></tr>\n";
    echo "<tr><td><b>Pracovný víkend:</b></td><td><select name=\"pracovny_vikend\"><option value=\"0\"" . (($over['pracovny_vikend'] == 0) ? " selected" : "") . ">nie</option><option value=\"1\"" . (($over['pracovny_vikend'] == 1) ? " selected" : "") . ">áno</option></select></td></tr>\n";
    echo "<tr><td><b>Pracovný sviatok:</b></td><td><select name=\"pracovny_sviatok\"><option value=\"0\"" . (($over['pracovny_sviatok'] == 0) ? " selected" : "") . ">nie</option><option value=\"1\"" . (($over['pracovny_sviatok'] == 1) ? " selected" : "") . ">áno</option></select></td></tr>\n";
    echo "<tr><td><b>Začiatok odovzdávania:</b></td><td><select name=\"zac_mesiac\">";
    $mesiace_s = "SELECT * FROM mesiac ORDER BY id ASC";
    $mesiace_q = MySQL_Query($mesiace_s);
    while ($mesiace = MySQL_Fetch_Array($mesiace_q)) {
        echo "<option value=\"" . $mesiace['id'] . "\"" . (($over['zac_mesiac'] == $mesiace['id']) ? " selected" : "") . ">" . $mesiace['nazov'] . "</option>";
    }
    echo "</select> <select name=\"zac_rok\">";
    $prvy_rok = 2009;
    $posledny_rok = Date("Y") + 1;
    for ($i = $prvy_rok; $i <= $posledny_rok; $i++) {
        echo "<option value=\"" . $i . "\"" . (($over['zac_rok'] == $i) ? " selected" : "") . ">" . $i . "</option>";
    }
    echo "</select></td></tr>\n";
    echo "<tr><td><b>Zodpovedná osoba v BMB:</b></td><td><select name=\"starost\"><option value=\"\">-- vyber --</option>";
    $star_s = "SELECT id,meno,priezvisko FROM user WHERE spolid = 0 AND admin = 0 ORDER BY priezvisko ASC";
    $star_q = MySQL_Query($star_s);
    while ($star = MySQL_Fetch_Array($star_q)) {
        echo "<option value=\"" . $star['id'] . "\"" . (($star['id'] == $over['uid']) ? " selected" : "") . ">" . $star['priezvisko'] . " " . $star['meno'] . "</option>";
    }
    echo "</select></td></tr>\n";
    echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_spol\" value=\"1\"><input type=\"submit\" value=\"Uložiť\"></td></tr>\n";
    echo "</table>\n";
    echo "</form>";
}

function pridat_spolocnost_uloz($ak_edit) {
    if (!Empty($_POST['nazov']) && !Empty($_POST['ulica']) && !Empty($_POST['psc']) && !Empty($_POST['mesto']) && !Empty($_POST['starost'])) {
        global $vypis;

        global $nazov_ok;
        $nazov_ok = Trim(HtmlSpecialChars($_POST['nazov'], ENT_QUOTES));
        global $ulica_ok;
        $ulica_ok = Trim(HtmlSpecialChars($_POST['ulica'], ENT_QUOTES));
        global $psc_ok;
        $psc_ok = Trim(HtmlSpecialChars($_POST['psc'], ENT_QUOTES));
        global $mesto_ok;
        $mesto_ok = Trim(HtmlSpecialChars($_POST['mesto'], ENT_QUOTES));
        global $starost_ok;
        $starost_ok = IntVal($_POST['starost']);
        global $typ_dochadzky_ok;
        $typ_dochadzky_ok = IntVal($_POST['typ_dochadzky']);
        global $pracovny_vikend_ok;
        $pracovny_vikend_ok = IntVal($_POST['pracovny_vikend']);
        global $pracovny_sviatok_ok;
        $pracovny_sviatok_ok = IntVal($_POST['pracovny_sviatok']);
        global $zac_mesiac_ok;
        $zac_mesiac_ok = IntVal($_POST['zac_mesiac']);
        global $zac_rok_ok;
        $zac_rok_ok = IntVal($_POST['zac_rok']);

        $star_s = "SELECT meno FROM user WHERE id = '" . $starost_ok . "' AND spolid = 0 AND admin = 0";
        $star_q = MySQL_Query($star_s);
        $star_n = MySQL_Num_Rows($star_q);
        if ($star_n != 1)
            UnSet($starost_ok);

        if ($ak_edit > 0) {
            $over_s = "SELECT * FROM spolocnost WHERE id = '" . $ak_edit . "' ";
            $over_q = MySQL_Query($over_s);
            $over_n = MySQL_Num_Rows($over_q);
            if ($over_n == 1)
                $over = MySQL_Fetch_Array($over_q);
            else
                $ak_edit = 0;
        }
        if (!Empty($nazov_ok) && !Empty($ulica_ok) && !Empty($psc_ok) && !Empty($mesto_ok) && !Empty($starost_ok) && !Empty($typ_dochadzky_ok)) {
            if ($ak_edit == 0) {
                $datcas_pridania = Date("Y-m-d H:i:s");
                $uloz_i = "INSERT INTO spolocnost (id, nazov, ulica, psc, mesto, dtid, pracovny_vikend, pracovny_sviatok, zac_mesiac, zac_rok, datum_pridania, uid ) VALUES (NULL, '" . $nazov_ok . "', '" . $ulica_ok . "', '" . $psc_ok . "', '" . $mesto_ok . "', '" . $typ_dochadzky_ok . "', '" . $pracovny_vikend_ok . "', '" . $pracovny_sviatok_ok . "', '" . $zac_mesiac_ok . "', '" . $zac_rok_ok . "', '" . $datcas_pridania . "', '" . $starost_ok . "')";
                $uloz_q = MySQL_Query($uloz_i);
            } else {
                $uloz_u = "UPDATE spolocnost SET nazov = '" . $nazov_ok . "', ulica = '" . $ulica_ok . "', psc = '" . $psc_ok . "', mesto = '" . $mesto_ok . "', dtid = '" . $typ_dochadzky_ok . "', pracovny_vikend = '" . $pracovny_vikend_ok . "', pracovny_sviatok = '" . $pracovny_sviatok_ok . "', zac_mesiac = '" . $zac_mesiac_ok . "', zac_rok = '" . $zac_rok_ok . "', uid = '" . $starost_ok . "' WHERE id = '" . $ak_edit . "' ";
                $uloz_q = MySQL_Query($uloz_u);
            }
            Header("Location: home.php?akc=1");
            exit();
        } else {
            $vypis = "Povinné údaje musia byť vyplnené!";
        }
    }
}

function profil_spolocnost($spolid) {
    echo "<h2>Spoločnosť</h2>\n";
    $over_s = "SELECT * FROM spolocnost WHERE id = '" . $spolid . "' ";
    $over_q = MySQL_Query($over_s);
    $over_n = MySQL_Num_Rows($over_q);
    if ($over_n == 1) {
        $over = MySQL_Fetch_Array($over_q);
        echo "<table>\n";
        echo "<tr><td>Názov:</td><td>" . $over['nazov'] . "</td></tr>\n";
        echo "<tr><td>Adresa:</td><td>" . $over['ulica'] . "<br />" . $over['psc'] . " " . $over['mesto'] . "</td></tr>\n";
        $typ_s = "SELECT * FROM dochadzka_typ WHERE id = '" . $over['dtid'] . "' ";
        $typ_q = MySQL_Query($typ_s);
        $typ = MySQL_Fetch_Array($typ_q);
        echo "<tr><td>Typ dochádzky:</td><td>" . $typ['typ'] . "</td></tr>\n";
        echo "<tr><td>Pracovný víkend:</td><td>" . (($over['pracovny_vikend'] == 1) ? "áno" : "nie") . "</td></tr>\n";
        echo "<tr><td>Pracovný sviatok:</td><td>" . (($over['pracovny_sviatok'] == 1) ? "áno" : "nie") . "</td></tr>\n";
        echo "<tr><td>Zodpovedná osoba v BMB:</td><td>" . starost_spol($spolid) . "</td></tr>\n";
        echo "</table>\n";
    } else {
        echo "Takáto spoločnosť neexistuje.";
    }
}

function pocet_prispievatelov($spolid) {
    $starost_s = "SELECT id FROM user WHERE spolid = '" . $spolid . "' ";
    $starost_q = MySQL_Query($starost_s);
    $starost_n = MySQL_Num_Rows($starost_q);
    return $starost_n;
}

function vyber_spol_prisp() {
    echo "<h2>Zobraziť prispieveteľov spoločnosti</h2>\n";

    echo "<select onChange=\"jm(this)\" size=\"1\"><option value=\"none\" selected>- - - vyber spoločnosť - - -</option>";
    $spol_s = "SELECT * FROM spolocnost ORDER BY nazov ASC";
    $spol_q = MySQL_Query($spol_s);
    while ($spol = MySQL_Fetch_Array($spol_q)) {
        echo "<option value=\"" . $spol['id'] . "\">" . $spol['nazov'] . "</option>";
    }
    echo "</select>\n";
    echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?akc=1&akc2=2&spolid=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
}

function zoznam_prispievatelov($spolid) {
    echo "<h2>Zoznam prispievateľov</h2>\n";
    $over_s = "SELECT * FROM spolocnost WHERE id = '" . $spolid . "' ";
    $over_q = MySQL_Query($over_s);
    $over_n = MySQL_Num_Rows($over_q);
    if ($over_n == 1) {
        $ord = Array("priezvisko", "mail");
        $order = IntVal($_GET['order']);
        if (Empty($ord[$order])) {
            $order_ok = $ord[0];
            $order_x = 0;
        } else {
            $order_ok = $ord[$order];
            $order_x = $order;
        }

        $a = Array("ASC", "DESC");
        $a_obr = Array("asc", "desc");
        $asc = IntVal($_GET['asc']);
        if (Empty($a[$asc])) {
            $asc_ok = $a[0];
            $asc_x = 0;
        } else {
            $asc_ok = $a[$asc];
            $asc_x = $asc;
        }
        $over = MySQL_Fetch_Array($over_q);
        $prisp_s = "SELECT * FROM user WHERE spolid = '" . $spolid . "' ORDER BY " . $order_ok . " " . $asc_ok;
        $prisp_q = MySQL_Query($prisp_s);
        echo "spoločnosti: <a href=\"home.php?akc=1&spolid=" . $over['id'] . "\">" . $over['nazov'] . "</a><br /><br />\n";
        echo "<a href=\"home.php?akc=1&akc2=3&spolid=" . $spolid . "\">* pridať nového prispievateľa</a><br />\n";
        echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
        echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=1&akc2=2&spolid=" . $spolid . "&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Meno:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=1&akc2=2&spolid=" . $spolid . "&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">E-mail:</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>&nbsp;</td></tr>\n";
        $i = 1;
        while ($prisp = MySQL_Fetch_Array($prisp_q)) {
            echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td><a href=\"home.php?akc=1&akc2=2&prispid=" . $prisp['id'] . "\">" . $prisp['priezvisko'] . " " . $prisp['meno'] . "</a></td><td>" . $prisp['mail'] . "</td><td><a href=\"home.php?akc=1&akc2=3&prispid=" . $prisp['id'] . "\">upraviť</a></td></tr>\n";
            $i++;
        }
        echo "</table>\n";
    } else {
        echo "Takáto spoločnosť neexistuje.";
    }
}

function pridat_prispievatela() {
    if (!Empty($_GET['spolid'])) {
        $spolid = IntVal($_GET['spolid']);
        echo "<h2>Pridať prispievateľa</h2>\n";
        $over_s = "SELECT nazov FROM spolocnost WHERE id = '" . $spolid . "' ";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n > 0) {
            $over = MySQL_Fetch_Array($over_q);
            echo "pre spoločnosť: " . $over['nazov'] . "<br />\n";
            $ak_edit = 0;
        } else {
            $vypis2 = "Takáto spoločnosť neexistuje.";
        }
    } elseif (!Empty($_GET['prispid'])) {
        $prispid = IntVal($_GET['prispid']);
        echo "<h2>Upraviť prispievateľa</h2>\n";
        $over1_s = "SELECT * FROM user WHERE id = '" . $prispid . "' AND spolid > 0";
        $over1_q = MySQL_Query($over1_s);
        $over1_n = MySQL_Num_Rows($over1_q);
        if ($over1_n > 0) {
            $over1 = MySQL_Fetch_Array($over1_q);
            $over_s = "SELECT nazov FROM spolocnost WHERE id = '" . $over1['spolid'] . "' ";
            $over_q = MySQL_Query($over_s);
            $over_n = MySQL_Num_Rows($over_q);
            if ($over_n > 0) {
                $over = MySQL_Fetch_Array($over_q);
                echo "spoločnosti: " . $over['nazov'] . "<br />\n";
                $ak_edit = $prispid;
            } else {
                $vypis2 = "Takáto spoločnosť neexistuje.";
            }
        } else {
            $vypis2 = "Takýto prispievateľ neexistuje.";
        }
    }

    if (Empty($vypis2)) {
        global $vypis;
        if (!Empty($vypis))
            echo $vypis . "<br />\n";

        $over_toto[] = "meno,Meno";
        $over_toto[] = "priezvisko,Priezvisko";
        $over_toto[] = "mail,E-mail";
        if ($ak_edit == 0) {
            $over_toto[] = "heslo,Heslo";
            $over_toto[] = "heslo2,Heslo-overenie";
        }

        check_js($over_toto);

        global $meno_ok;
        global $priezvisko_ok;
        global $mail_ok;
        global $tel_ok;
        global $ip_ok;

        echo "<form action=\"home.php?akc=1&akc3=1&" . (($ak_edit == 0) ? "spolid=" . $spolid : "prispid=" . $prispid) . "\" method=\"post\" name=\"formular\" onsubmit=\"return check();\">\n";
        echo "<table>\n";
        echo "<tr><td><b>Meno:</b></td><td><input type=\"text\" name=\"meno\" value=\"" . (($_POST['meno']) ? $meno_ok : $over1['meno']) . "\"></td></tr>\n";
        echo "<tr><td><b>Priezvisko:</b></td><td><input type=\"text\" name=\"priezvisko\" value=\"" . (($_POST['priezvisko']) ? $priezvisko_ok : $over1['priezvisko']) . "\"></td></tr>\n";
        echo "<tr><td><b>E-mail:</b></td><td><input type=\"text\" name=\"mail\" value=\"" . (($_POST['mail']) ? $mail_ok : $over1['mail']) . "\"></td></tr>\n";
        echo "<tr><td>" . (($ak_edit > 0) ? "" : "<b>") . "Heslo:" . (($ak_edit > 0) ? "" : "</b>") . "</td><td><input type=\"password\" name=\"heslo\" value=\"\"></td></tr>\n";
        echo "<tr><td>" . (($ak_edit > 0) ? "" : "<b>") . "Heslo-overenie:" . (($ak_edit > 0) ? "" : "</b>") . "</td><td><input type=\"password\" name=\"heslo2\" value=\"\"></td></tr>\n";
        if ($ak_edit > 0)
            echo "<tr><td colspan=\"2\">Ak chcete tomuto prispievateľovi zmeniť heslo, zadajte do oboch kolóniek nové heslo. Ak nie, nechajte obe prázdne.</td></tr>\n";
        echo "<tr><td><b>Prístup:</b></td><td><select name=\"pristup\">";
        $pristupy_s = "SELECT * FROM pristup_prisp ORDER BY pristup ASC";
        $pristupy_q = MySQL_Query($pristupy_s);
        while ($pristupy = MySQL_Fetch_Array($pristupy_q)) {
            echo "<option value=\"" . $pristupy['pristup'] . "\"";
            if ($pristupy['pristup'] == $over1['admin'])
                echo " selected";
            echo ">" . $pristupy['nazov1'] . "</option>";
        }
        echo "</select></td></tr>\n";
        if (Empty($_GET['spolid'])) {
            if ($over1['notifikacia'] == 1)
                $notif_zaskrt = 1;
            else
                $notif_zaskrt = 0;
        }
        else {
            $notif_zaskrt = 1;
        }
        echo "<tr><td>Posielať notifikácie:</td><td><input type=\"checkbox\" name=\"notif\" value=\"1\" " . (($notif_zaskrt == 1) ? " checked" : "") . "></td></tr>\n";
        echo "<tr><td>Telefón:</td><td><input type=\"text\" name=\"tel\" value=\"" . (($_POST['meno']) ? $tel_ok : $over1['tel']) . "\"></td></tr>\n";
        echo "<tr><td>IP adresa:</td><td><input type=\"text\" name=\"ip\" value=\"" . (($_POST['meno']) ? $ip_ok : $over1['ip']) . "\"></td></tr>\n";
        echo "<tr><td colspan=\"2\">Ak vyplníte IP adresu, tak tento prispievateľ sa bude môcť prihlásiť len z nej.<br />Ak chcete zadať viac adries, oddelte ich čiarkou. Ak necháte prázdne, tak sa môže prihlásiť odkialkoľvek.</td></tr>\n";
        echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_prisp\" value=\"1\"><input type=\"submit\" value=\"Uložiť\"></td></tr>\n";
        echo "</table>\n";
        echo "</form>";
    } else {
        echo $vypis;
    }
}

function pridat_prispievatela_uloz() {
    if (!Empty($_GET['spolid'])) {
        $spolid = IntVal($_GET['spolid']);
        $over_s = "SELECT nazov FROM spolocnost WHERE id = '" . $spolid . "' ";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n > 0) {
            $ak_edit = 0;
        } else {
            Header("Location: index.php");
            exit();
        }
    } elseif (!Empty($_GET['prispid'])) {
        $prispid = IntVal($_GET['prispid']);
        $over1_s = "SELECT * FROM user WHERE id = '" . $prispid . "' AND spolid > 0";
        $over1_q = MySQL_Query($over1_s);
        $over1_n = MySQL_Num_Rows($over1_q);
        if ($over1_n > 0) {
            $over1 = MySQL_Fetch_Array($over1_q);
            $spolid = $over1['spolid'];
            $ak_edit = $prispid;
        } else {
            Header("Location: index.php");
            exit();
        }
    }

    if (!Empty($_POST['meno']) && !Empty($_POST['priezvisko']) && !Empty($_POST['mail'])) {
        global $vypis;

        global $meno_ok;
        $meno_ok = Trim(HtmlSpecialChars($_POST['meno'], ENT_QUOTES));
        global $priezvisko_ok;
        $priezvisko_ok = Trim(HtmlSpecialChars($_POST['priezvisko'], ENT_QUOTES));
        global $mail_ok;
        $mail_ok = Trim(HtmlSpecialChars($_POST['mail'], ENT_QUOTES));
        if (!Empty($_POST['heslo']))
            $heslo_ok = Trim(MD5($_POST['heslo']));
        else
            $heslo_ok = "";
        global $tel_ok;
        $tel_ok = Trim(HtmlSpecialChars($_POST['tel'], ENT_QUOTES));
        global $ip_ok;
        $ip_ok = Trim(HtmlSpecialChars($_POST['ip'], ENT_QUOTES));
        global $pristup_ok;
        $pristup_ok = IntVal($_POST['pristup']);
        global $notif_ok;
        $notif_ok = IntVal($_POST['notif']);

        if (($ak_edit == 0 && !Empty($_POST['heslo']) && !Empty($_POST['heslo2'])) || ($ak_edit > 0)) {
            if ($_POST['heslo'] == $_POST['heslo2']) {
                if (Eregi("^[_a-zA-Z0-9]+([-\.][_a-zA-Z0-9]+)*@[_a-zA-Z0-9]+([-\.][_a-zA-Z0-9]+)*\.[_a-zA-Z0-9]{2,4}$", $mail_ok)) {
                    $over_mail_s = "SELECT id FROM user WHERE mail = '" . $mail_ok . "' ";
                    $over_mail_q = MySQL_Query($over_mail_s);
                    $over_mail_n = MySQL_Num_Rows($over_mail_q);
                    $over_mail2_s = "SELECT id FROM z WHERE mail = '" . $mail_ok . "' ";
                    $over_mail2_q = MySQL_Query($over_mail2_s);
                    $over_mail2_n = MySQL_Num_Rows($over_mail2_q);
                    if ($over_mail_n == 0 || $over_mail2_n == 0 || $ak_edit > 0) {
                        if (!Empty($meno_ok) && !Empty($priezvisko_ok) && !Empty($mail_ok)) {
                            if ($ak_edit == 0) {
                                $uloz_i = "INSERT INTO user (id, spolid, meno, priezvisko, mail, heslo, tel, admin, ip, notifikacia, active, lang) VALUES (NULL, '" . $spolid . "', '" . $meno_ok . "', '" . $priezvisko_ok . "', '" . $mail_ok . "', '" . $heslo_ok . "', '" . $tel_ok . "', '" . $pristup_ok . "', '" . $ip_ok . "', '" . $notif_ok . "', 1, 0)";
                                $uloz_q = MySQL_Query($uloz_i);
                            } else {
                                $uloz_u = "UPDATE user SET meno = '" . $meno_ok . "', priezvisko = '" . $priezvisko_ok . "', mail = '" . $mail_ok . "'";
                                if (!Empty($heslo_ok))
                                    $uloz_u .= ", heslo = '" . $heslo_ok . "'";
                                $uloz_u .= ", tel = '" . $tel_ok . "', admin = '" . $pristup_ok . "', ip = '" . $ip_ok . "', notifikacia = '" . $notif_ok . "' WHERE id = '" . $ak_edit . "' ";
                                $uloz_q = MySQL_Query($uloz_u);
                            }
                            Header("Location: home.php?akc=1&akc2=2&spolid=$spolid");
                            exit();
                        }
                        else {
                            $vypis = "Povinné údaje musia byť vyplnené!";
                        }
                    } else {
                        $vypis = "Zadaný e-mail už je použitý!";
                    }
                } else {
                    $vypis = "Zadaný e-mail nie je v správnom tvare!";
                }
            } else {
                $vypis = "Zadané heslá nie sú rovnaké!";
            }
        } else {
            $vypis = "Heslo musí byť vyplnené!";
        }
    }
}

function profil_prispievatela($prispid) {
    echo "<h2>Prispievateľ</h2>\n";
    $over_s = "SELECT * FROM user WHERE id = '" . $prispid . "' AND spolid > 0";
    $over_q = MySQL_Query($over_s);
    $over_n = MySQL_Num_Rows($over_q);
    if ($over_n == 1) {
        $over = MySQL_Fetch_Array($over_q);
        echo "<table>\n";
        echo "<tr><td>Meno:</td><td>" . $over['meno'] . " " . $over['priezvisko'] . "</td></tr>\n";
        echo "<tr><td>E-mail:</td><td>" . $over['mail'] . "</td></tr>\n";
        echo "<tr><td>Telefón:</td><td>" . $over['tel'] . "</td></tr>\n";
        echo "<tr><td>IP adresa:</td><td>" . $over['ip'] . "</td></tr>\n";
        $spol_s = "SELECT nazov FROM spolocnost WHERE id = " . $over['spolid'];
        $spol_q = MySQL_Query($spol_s);
        $spol = MySQL_Fetch_Array($spol_q);
        echo "<tr><td>Spoločnosť:</td><td><a href=\"home.php?akc=1&spolid=" . $over['spolid'] . "\">" . $spol['nazov'] . "</a></td></tr>\n";
        echo "</table>\n";
    } else {
        echo "Takýto prispievateľ neexistuje.";
    }
}

function spolid_prihlaseneho($veduci = false) {
    global $user_id;
    if (!$veduci)
        $about_user_s = "SELECT spolid FROM user WHERE id = '" . $user_id . "' ";
    else
        $about_user_s = "SELECT spolid FROM z WHERE id = '" . $user_id . "' ";
    $about_user_q = MySQL_Query($about_user_s);
    $about_user = MySQL_Fetch_Array($about_user_q);
    return $about_user['spolid'];
}

function z_pocet_dok($zid) {
    $pocet_s = "SELECT id FROM z_docs WHERE zid = '" . $zid . "' ";
    $pocet_q = MySQL_Query($pocet_s);
    $pocet_n = MySQL_Num_Rows($pocet_q);
    return $pocet_n;
}

function zoznam_zamestnancov_spol($spolid, $falkModeAdmin = false) {
    if (!isset($_SESSION['zobraz_zam'])) {
        $_SESSION['zobraz_zam'] = 1;
    }
    global $veduci_oddelenia, $user_id;
    $ord = Array("z.priezvisko", "stav.stav", "z.datum_prichodu", "z.datum_zmeny");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }
    if (($falkModeAdmin)) {
        echo "<h2>" . preklad(7) . "</h2>\n";
        echo "<select onChange=\"jm(this)\" size=\"1\"><option value=\"0\"" . (($_SESSION['zobraz_zam'] == 0) ? " selected" : "") . ">všetci</option>";
        $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
        $stavy_q = MySQL_Query($stavy_s);
        while ($stavy = MySQL_Fetch_Array($stavy_q)) {
            echo "<option value=\"" . $stavy['id'] . "\"" . (($_SESSION['zobraz_zam'] == $stavy['id']) ? " selected" : "") . ">" . preklad($stavy['jazyk_id']) . "</option>";
        }
        echo "</select>\n";
        echo "<a href=\"home.php?akc=3&akc2=1\">* " . preklad(8) . "</a><br />\n";
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?b=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
        echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
        echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=3&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(9) . "</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>" . preklad(144) . ":</td><td>" . preklad(148) . "</td><td><a href=\"?akc=3&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(10) . "</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=3&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(11) . "</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=3&order=3&asc=" . (($order_x == 3 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(12) . "</a>" . (($order_x == 3) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>" . preklad(13) . "</td><td>" . preklad(14) . "</td><td>&nbsp;</td></tr>\n";
        $akt_dat = Date("Y-m-d");
        $zam_s = "SELECT z.*,stav.stav FROM z,stav WHERE spolid = '" . $spolid . "' AND stav.id = z.stavid ";
        if ($_SESSION['zobraz_zam'] > 0)
            $zam_s .= "AND stavid = '" . $_SESSION['zobraz_zam'] . "' ";
        else
            $zam_s .= "";
        $zam_s .= "ORDER BY " . $order_ok . " " . $asc_ok;
        $zam_q = MySQL_Query($zam_s);
        $i = 1;
        while ($zam = MySQL_Fetch_Array($zam_q)) {
            echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td>" . $zam['priezvisko'] . " " . $zam['meno'] . "</td>";
            echo '<td>';
            if ($zam['manager'] == 1) {
                if ($zam['veduci_oddelenia']) {
                    echo preklad(139);
                } else {
                    echo preklad(140);
                }
            } elseif ($zam['manager'] == 2) {
                echo preklad(158);
            } else {
                echo preklad(146);
            }
            echo '</td>';
            echo "<td>" . $zam['pozicia'] . "</td><td>" . $zam['stav'] . "</td><td>" . date_conv_to_view($zam['datum_prichodu']) . "</td><td>" . date_conv_to_view($zam['datum_zmeny']) . "</td><td align=\"center\">" . z_pocet_dok($zam['id']) . "</td><td><a href=\"home.php?akc=3&akc2=2&zid=" . $zam['id'] . "\">" . preklad(15) . "</a> <a href=\"home.php?akc=3&akc2=3&zid=" . $zam['id'] . "\">" . preklad(16) . "</a></td><td><a href=\"home.php?akc=3&akc2=4&zid=" . $zam['id'] . "\">" . preklad(17) . "</a></td></tr>\n";
            $i++;
        }
        echo "</table>";
    } elseif ($veduci_oddelenia != 0) {
        echo "<h2>" . preklad(7) . "</h2>\n";
        echo "<select onChange=\"jm(this)\" size=\"1\"><option value=\"0\"" . (($_SESSION['zobraz_zam'] == 0) ? " selected" : "") . ">všetci</option>";
        $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
        $stavy_q = MySQL_Query($stavy_s);
        while ($stavy = MySQL_Fetch_Array($stavy_q)) {
            echo "<option value=\"" . $stavy['id'] . "\"" . (($_SESSION['zobraz_zam'] == $stavy['id']) ? " selected" : "") . ">" . preklad($stavy['jazyk_id']) . "</option>";
        }
        echo "</select>\n";
        echo "<a href=\"home.php?akc=3&akc2=1\">* " . preklad(8) . "</a><br />\n";
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?b=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
        echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
        echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=3&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(9) . "</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>" . preklad(144) . ":</td><td>" . preklad(148) . "</td><td><a href=\"?akc=3&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(11) . "</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=3&order=3&asc=" . (($order_x == 3 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(12) . "</a>" . (($order_x == 3) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>" . preklad(13) . "</td><td>" . preklad(14) . "</td><td>&nbsp;</td></tr>\n";
        $akt_dat = Date("Y-m-d");
        $zam_s = "SELECT z.*,stav.stav FROM z,stav WHERE veduci_oddelenia=0 AND spolid = '" . $spolid . "' AND stav.id = z.stavid AND z.patri_k='" . $veduci_oddelenia . "' ";
        if ($_SESSION['zobraz_zam'] > 0)
            $zam_s .= "AND stavid = '" . $_SESSION['zobraz_zam'] . "' ";
        else
            $zam_s .= "";
        $zam_s .= "ORDER BY " . $order_ok . " " . $asc_ok;
        $zam_q = MySQL_Query($zam_s);
        $i = 1;
        while ($zam = MySQL_Fetch_Array($zam_q)) {
            echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td>" . $zam['priezvisko'] . " " . $zam['meno'] . "</td>";
            echo '<td>';
            if ($zam['manager'] == 1) {
                if ($zam['veduci_oddelenia']) {
                    echo preklad(139);
                } else {
                    echo preklad(140);
                }
            } elseif ($zam['manager'] == 2) {
                echo preklad(158);
            } else {
                echo preklad(146);
            }
            echo '</td>';
            echo "<td>" . $zam['pozicia'] . "</td><td>" . date_conv_to_view($zam['datum_prichodu']) . "</td><td>" . date_conv_to_view($zam['datum_zmeny']) . "</td><td align=\"center\">" . z_pocet_dok($zam['id']) . "</td><td><a href=\"home.php?akc=3&akc2=2&zid=" . $zam['id'] . "\">" . preklad(15) . "</a> <a href=\"home.php?akc=3&akc2=3&zid=" . $zam['id'] . "\">" . preklad(16) . "</a></td><td><a href=\"home.php?akc=3&akc2=4&zid=" . $zam['id'] . "\">" . preklad(17) . "</a></td></tr>\n";
            $i++;
        }
        echo "</table>";
    } else {
        echo "<h2>" . preklad(7) . "</h2>\n";
        echo "<select onChange=\"jm(this)\" size=\"1\"><option value=\"0\"" . (($_SESSION['zobraz_zam'] == 0) ? " selected" : "") . ">všetci</option>";
        $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
        $stavy_q = MySQL_Query($stavy_s);
        while ($stavy = MySQL_Fetch_Array($stavy_q)) {
            echo "<option value=\"" . $stavy['id'] . "\"" . (($_SESSION['zobraz_zam'] == $stavy['id']) ? " selected" : "") . ">" . preklad($stavy['jazyk_id']) . "</option>";
        }
        echo "</select>\n";
        echo "<a href=\"home.php?akc=3&akc2=1\">* " . preklad(8) . "</a><br />\n";
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?b=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
        echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
        echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=3&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(9) . "</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=3&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(10) . "</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=3&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(11) . "</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=3&order=3&asc=" . (($order_x == 3 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">" . preklad(12) . "</a>" . (($order_x == 3) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>" . preklad(13) . "</td><td>" . preklad(14) . "</td><td>&nbsp;</td></tr>\n";
        $akt_dat = Date("Y-m-d");
        $zam_s = "SELECT z.id,z.spolid,z.datum_pridania,z.datum_prichodu,z.datum_odchodu,z.meno,z.priezvisko,z.datum_zmeny,z.stavid,z.active,stav.stav FROM z,stav WHERE spolid = '" . $spolid . "' AND stav.id = z.stavid ";
        if ($_SESSION['zobraz_zam'] > 0)
            $zam_s .= "AND stavid = '" . $_SESSION['zobraz_zam'] . "' ";
        else
            $zam_s .= "";
        $zam_s .= "ORDER BY " . $order_ok . " " . $asc_ok;
        $zam_q = MySQL_Query($zam_s);
        $i = 1;
        while ($zam = MySQL_Fetch_Array($zam_q)) {
            echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td>" . $zam['priezvisko'] . " " . $zam['meno'] . "</td><td>" . $zam['stav'] . "</td><td>" . date_conv_to_view($zam['datum_prichodu']) . "</td><td>" . date_conv_to_view($zam['datum_zmeny']) . "</td><td align=\"center\">" . z_pocet_dok($zam['id']) . "</td><td><a href=\"home.php?akc=3&akc2=2&zid=" . $zam['id'] . "\">" . preklad(15) . "</a> <a href=\"home.php?akc=3&akc2=3&zid=" . $zam['id'] . "\">" . preklad(16) . "</a></td><td><a href=\"home.php?akc=3&akc2=4&zid=" . $zam['id'] . "\">" . preklad(17) . "</a></td></tr>\n";
            $i++;
        }
        echo "</table>";
    }
}

function pridat_zamestnanca_spol($falkModeAdmin = false) {
    global $veduci_oddelenia;
    global $vypis;

    global $priezvisko_ok;
    global $meno_ok;
    global $titul_ok;
    global $priezvisko_rodne_ok;
    global $rodne_cislo1_ok;
    global $rodne_cislo2_ok;
    global $datum_narodenia_ok;
    global $miesto_narodenia_ok;
    global $tel_cislo_ok;
    global $narodnost_ok;
    global $statna_prislusnost_ok;
    global $obciansky_preukaz_ok;
    global $vodicsky_preukaz_ok;
    global $rodinny_stav_ok;
    global $zdravotny_stav_ok;
    global $poistovna_ok;
    global $t_ulica_ok;
    global $t_mesto_ok;
    global $t_psc_ok;
    global $t_tel_ok;
    global $p_ulica_ok;
    global $p_mesto_ok;
    global $p_psc_ok;
    global $p_tel_ok;
    global $pred_ok;
    global $ucet_ok;
    global $banka_ok;
    global $datum_nastupu_ok;
    global $druh_pomeru_ok;
    global $datum_ukoncenia_ok;
    global $ostatne_ok;
    global $stav_ok;
    $over_toto[] = "priezvisko,Priezvisko";
    $over_toto[] = "meno,Meno";
    $over_toto[] = "priezvisko_rodne,Rodné priezvisko";
    $over_toto[] = "rodne_cislo1,Rodné číslo";
    $over_toto[] = "rodne_cislo2,Rodné číslo";
    $over_toto[] = "datum_narodenia,Dátum narodenia";
    $over_toto[] = "miesto_narodenia,Miesto narodenia";
    $over_toto[] = "narodnost,Národnosť";
    $over_toto[] = "statna_prislusnost,Štátna príslušnosť";
    $over_toto[] = "rodinny_stav,Rodinný stav";
    $over_toto[] = "poistovna,Zdravotná poistovna";
    $over_toto[] = "t_ulica,Ulica";
    $over_toto[] = "t_mesto,Mesto/obec";
    $over_toto[] = "t_psc,PSČ";
    $over_toto[] = "banka,Názov banky";
    $over_toto[] = "ucet,Číslo účtu";
    $over_toto[] = "datum_nastupu,Dátum nástupu do zamestnania";
    $over_toto[] = "druh_pomeru,Druh pracovného pomeru";
    $over_toto[] = "stav,Stav";

    check_js($over_toto);
    if ($falkModeAdmin) {
        echo "<h2>" . preklad(18) . "</h2>\n";
    } else {
        echo "<h2>" . preklad(18) . "</h2>\n";
    }
    echo "<form action=\"home.php?akc=3&akc2=1\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\" onsubmit=\"return check();\">\n";
    echo "<table>\n";
    echo "<tr><td colspan=\"2\"><b><u>" . preklad(19) . "</u></b></td></tr>\n";
    echo "<tr><td><b>" . preklad(20) . "</b></td><td><input type=\"text\" name=\"priezvisko\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(21) . "</b></td><td><input type=\"text\" name=\"meno\" /></td></tr>\n";
    echo "<tr><td>" . preklad(22) . "</td><td><input type=\"text\" name=\"titul\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(23) . "</b></td><td><input type=\"text\" name=\"priezvisko_rodne\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(24) . "</b></td><td><input type=\"text\" name=\"rodne_cislo1\" maxlength=\"6\" /> / <input type=\"text\" name=\"rodne_cislo2\" maxlength=\"4\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(25) . "</b></td><td><input type=\"text\" name=\"datum_narodenia\" id=\"datum_narodenia\" /> <a href=\"javascript:NewCssCal('datum_narodenia','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a></td></tr>\n";
    echo "<tr><td><b>" . preklad(26) . "</b></td><td><input type=\"text\" name=\"miesto_narodenia\" /></td></tr>\n";
    echo "<tr><td>" . preklad(27) . "</td><td><input type=\"text\" name=\"tel_cislo\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(28) . "</b></td><td><input type=\"text\" name=\"narodnost\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(29) . "</b></td><td><input type=\"text\" name=\"statna_prislusnost\" /></td></tr>\n";
    echo "<tr><td>" . preklad(30) . "</td><td><input type=\"text\" name=\"obciansky_preukaz\" /></td></tr>\n";
    echo "<tr><td>" . preklad(31) . "</td><td><input type=\"text\" name=\"vodicsky_preukaz\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(32) . "</b></td><td><input type=\"text\" name=\"rodinny_stav\" /></td></tr>\n";
    echo "<tr><td>" . preklad(33) . "</td><td><input type=\"text\" name=\"zdravotny_stav\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(34) . "</b></td><td><select name=\"poistovna\"><option value=\"\">" . preklad(50) . "</option>";
    $poistovne_s = "SELECT * FROM poistovna ORDER BY nazov ASC";
    $poistovne_q = MySQL_Query($poistovne_s);
    while ($poistovne = MySQL_Fetch_Array($poistovne_q)) {
        echo "<option value=\"" . $poistovne['id'] . "\">" . $poistovne['nazov'] . "</option>";
    }
    echo "</select></td></tr>\n";
    echo "<tr><td colspan=\"2\"><b><u>" . preklad(35) . "</u></b></td></tr>\n";
    echo "<tr><td><b>" . preklad(36) . "</b></td><td><input type=\"text\" name=\"t_ulica\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(37) . "</b></td><td><input type=\"text\" name=\"t_mesto\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(38) . "</b></td><td><input type=\"text\" name=\"t_psc\" /></td></tr>\n";
    echo "<tr><td>" . preklad(39) . "</td><td><input type=\"text\" name=\"t_tel\" /></td></tr>\n";
    echo "<tr><td colspan=\"2\"><b><u>" . preklad(40) . "</u></b></td></tr>\n";
    echo "<tr><td>" . preklad(36) . "</td><td><input type=\"text\" name=\"p_ulica\" /></td></tr>\n";
    echo "<tr><td>" . preklad(37) . "</td><td><input type=\"text\" name=\"p_mesto\" /></td></tr>\n";
    echo "<tr><td>" . preklad(38) . "</td><td><input type=\"text\" name=\"p_psc\" /></td></tr>\n";
    echo "<tr><td>" . preklad(39) . "</td><td><input type=\"text\" name=\"p_tel\" /></td></tr>\n";
    echo "<tr><td colspan=\"2\"><b><u>" . preklad(41) . "</u></b></td></tr>\n";
    echo "<tr><td>" . preklad(42) . " - <b>" . preklad(43) . "</b></td><td><input type=\"text\" name=\"pred\" maxlength=\"6\" /> - <input type=\"text\" name=\"ucet\" maxlength=\"10\" /> / <select name=\"banka\"><option value=\"\">" . preklad(50) . "</option>";
    $banky_s = "SELECT * FROM banka ORDER BY kod ASC";
    $banky_q = MySQL_Query($banky_s);
    while ($banky = MySQL_Fetch_Array($banky_q)) {
        echo "<option value=\"" . $banky['kod'] . "\">" . $banky['kod'] . " - " . $banky['nazov'] . "</option>";
    }
    echo "</select></td></tr>\n";
    echo "<tr><td colspan=\"2\"><b><u>" . preklad(44) . "</u></b></td></tr>\n";
    echo "<tr><td><b>" . preklad(45) . "</b></td><td><input type=\"text\" name=\"datum_nastupu\" id=\"datum_nastupu\" readonly /> <a href=\"javascript:NewCssCal('datum_nastupu','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a></td></tr>\n";
    echo "<tr><td><b>" . preklad(46) . "</b></td><td><input type=\"text\" name=\"druh_pomeru\" /></td></tr>\n";
    echo "<tr><td>" . preklad(47) . "</td><td><input type=\"text\" name=\"datum_ukoncenia\" id=\"datum_ukoncenia\" readonly /> <a href=\"javascript:NewCssCal('datum_ukoncenia','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a></td></tr>\n";
    echo "<tr><td>" . preklad(48) . "</td><td><textarea name=\"ostatne\" rows=\"8\" cols=\"50\"></textarea></td></tr>\n";
    echo "<tr><td><b>" . preklad(49) . "</b></td><td><select name=\"stav\">";
    $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
    $stavy_q = MySQL_Query($stavy_s);
    while ($stavy = MySQL_Fetch_Array($stavy_q)) {
        echo "<option value=\"" . $stavy['id'] . "\">" . preklad($stavy['jazyk_id']) . "</option>";
    }
    echo "</select></td></tr>\n";
    if ($falkModeAdmin) {
        echo "<tr><td><b>" . preklad(157) . ":</b></td>";
        echo "<td>";
        echo '<select id="manazer" onchange="vyberVeduceho()" name="manazer">';
        echo '<option value="0">Zamestnanec</option>';
        echo '<option value="1">Manažér</option>';
        echo '<option value="2">Dohodár</option>';
        echo '</select>';
        echo "</td></tr>";
        echo "<tr id=\"vyberVeduceho\"><td><b>" . preklad(141) . ":</b></td>";
        echo "<td>";
        echo '<select name="patriK" size="1">';
        $pr_s = "SELECT * FROM oddelenie ORDER BY nazov";
        $pr_q = MySQL_Query($pr_s);
        while ($pr = MySQL_Fetch_Array($pr_q)) {
            echo "<option value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
        }
        echo '</select>';
        echo "</td></tr>";
        echo "<tr id=\"manazer_oddelenia\" style=\"display: none\">";
        echo "<td><b>" . preklad(139) . ":</b></td>";
        echo "<td><select name=\"manazer_oddelenia\" size=\"1\">";
        echo '<option value="0">' . preklad(156) . '</option>';
        $pr_s = "SELECT * FROM oddelenie ORDER BY nazov";
        $pr_q = MySQL_Query($pr_s);
        while ($pr = MySQL_Fetch_Array($pr_q)) {
            echo "<option value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
        }
        echo "</select></td>";
        echo "</tr>";
        echo "<tr id=\"pozicia\"><td><b>" . preklad(148) . "</b></td>";
        echo "<td><input type=\"text\" name=\"pozicia\" /></td></tr>";
        echo "<tr id=\"osobneCislo\"><td><b>" . preklad(149) . "</b></td>";
        echo "<td><input type=\"text\" name=\"osobneCislo\" /></td></tr>";
        echo "<tr id=\"costCenter\"><td><b>" . preklad(150) . "</b></td>";
        echo "<td><input type=\"text\" name=\"costCenter\" /></td></tr>";
        echo "<tr id=\"fond\"><td><b>" . preklad(151) . "</b></td>";
        echo "<td><input type=\"text\" name=\"fond\" /></td></tr>";
        echo "<tr><td colspan=\"2\">" . form_viac_suborov(5) . "</td></tr>\n";
        echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_zam_spol\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" /></td></tr>\n";
    } elseif ($veduci_oddelenia != 0) {
        echo "<tr id=\"pozicia\"><td><b>" . preklad(148) . "</b></td>";
        echo "<td><input type=\"text\" name=\"pozicia\" /></td></tr>";
        echo "<tr id=\"osobneCislo\"><td><b>" . preklad(149) . "</b></td>";
        echo "<td><input type=\"text\" name=\"osobneCislo\" /></td></tr>";
        echo "<tr id=\"costCenter\"><td><b>" . preklad(150) . "</b></td>";
        echo "<td><input type=\"text\" name=\"costCenter\" /></td></tr>";
        echo "<tr id=\"fond\"><td><b>" . preklad(151) . "</b></td>";
        echo "<td><input type=\"text\" name=\"fond\" /></td></tr>";
        echo "<tr><td colspan=\"2\">" . form_viac_suborov(5) . "</td></tr>\n";
        echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_zam_spol\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" /></td></tr>\n";
    } else {
        echo "<tr><td colspan=\"2\">" . form_viac_suborov(5) . "</td></tr>\n";
        echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_zam_spol\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" /></td></tr>\n";
    }

    echo "</table>\n";
    echo "</form>\n";
}

function pridat_zamestnanca_spol_uloz($falkModeAdmin = false) {
    if (!Empty($_POST['priezvisko']) && !Empty($_POST['meno']) && !Empty($_POST['priezvisko_rodne']) && !Empty($_POST['rodne_cislo1']) && !Empty($_POST['rodne_cislo2']) && !Empty($_POST['datum_narodenia']) && !Empty($_POST['miesto_narodenia']) && !Empty($_POST['narodnost']) && !Empty($_POST['statna_prislusnost']) && !Empty($_POST['rodinny_stav']) && !Empty($_POST['poistovna']) && !Empty($_POST['t_ulica']) && !Empty($_POST['t_mesto']) && !Empty($_POST['t_psc']) && !Empty($_POST['banka']) && !Empty($_POST['ucet']) && !Empty($_POST['datum_nastupu']) && !Empty($_POST['druh_pomeru'])) {
        global $vypis;
        global $priezvisko_ok;
        $priezvisko_ok = Trim(HtmlSpecialChars($_POST['priezvisko'], ENT_QUOTES));
        global $meno_ok;
        $meno_ok = Trim(HtmlSpecialChars($_POST['meno'], ENT_QUOTES));
        global $titul_ok;
        $titul_ok = Trim(HtmlSpecialChars($_POST['titul'], ENT_QUOTES));
        global $priezvisko_rodne_ok;
        $priezvisko_rodne_ok = Trim(HtmlSpecialChars($_POST['priezvisko_rodne'], ENT_QUOTES));
        global $rodne_cislo1_ok;
        $rodne_cislo1_ok = Trim(HtmlSpecialChars($_POST['rodne_cislo1'], ENT_QUOTES));
        global $rodne_cislo2_ok;
        $rodne_cislo2_ok = Trim(HtmlSpecialChars($_POST['rodne_cislo2'], ENT_QUOTES));
        global $datum_narodenia_ok;
        $datum_narodenia_ok = Trim(HtmlSpecialChars($_POST['datum_narodenia'], ENT_QUOTES));
        $datum_narodenia_db = date_conv_to_db("$datum_narodenia_ok");
        global $miesto_narodenia_ok;
        $miesto_narodenia_ok = Trim(HtmlSpecialChars($_POST['miesto_narodenia'], ENT_QUOTES));
        global $tel_cislo_ok;
        $tel_cislo_ok = Trim(HtmlSpecialChars($_POST['tel_cislo'], ENT_QUOTES));
        global $narodnost_ok;
        $narodnost_ok = Trim(HtmlSpecialChars($_POST['narodnost'], ENT_QUOTES));
        global $statna_prislusnost_ok;
        $statna_prislusnost_ok = Trim(HtmlSpecialChars($_POST['statna_prislusnost'], ENT_QUOTES));
        global $obciansky_preukaz_ok;
        $obciansky_preukaz_ok = Trim(HtmlSpecialChars($_POST['obciansky_preukaz'], ENT_QUOTES));
        global $vodicsky_preukaz_ok;
        $vodicsky_preukaz_ok = Trim(HtmlSpecialChars($_POST['vodicsky_preukaz'], ENT_QUOTES));
        global $rodinny_stav_ok;
        $rodinny_stav_ok = Trim(HtmlSpecialChars($_POST['rodinny_stav'], ENT_QUOTES));
        global $zdravotny_stav_ok;
        $zdravotny_stav_ok = Trim(HtmlSpecialChars($_POST['zdravotny_stav'], ENT_QUOTES));
        global $poistovna_ok;
        $poistovna_ok = IntVal($_POST['poistovna']);
        global $t_ulica_ok;
        $t_ulica_ok = Trim(HtmlSpecialChars($_POST['t_ulica'], ENT_QUOTES));
        global $t_mesto_ok;
        $t_mesto_ok = Trim(HtmlSpecialChars($_POST['t_mesto'], ENT_QUOTES));
        global $t_psc_ok;
        $t_psc_ok = Trim(HtmlSpecialChars($_POST['t_psc'], ENT_QUOTES));
        global $t_tel_ok;
        $t_tel_ok = Trim(HtmlSpecialChars($_POST['t_tel'], ENT_QUOTES));
        global $p_ulica_ok;
        $p_ulica_ok = Trim(HtmlSpecialChars($_POST['p_ulica'], ENT_QUOTES));
        global $p_mesto_ok;
        $p_mesto_ok = Trim(HtmlSpecialChars($_POST['p_mesto'], ENT_QUOTES));
        global $p_psc_ok;
        $p_psc_ok = Trim(HtmlSpecialChars($_POST['p_psc'], ENT_QUOTES));
        global $p_tel_ok;
        $p_tel_ok = Trim(HtmlSpecialChars($_POST['p_tel'], ENT_QUOTES));
        global $pred_ok;
        $pred_ok = Trim(HtmlSpecialChars($_POST['pred'], ENT_QUOTES));
        global $ucet_ok;
        $ucet_ok = Trim(HtmlSpecialChars($_POST['ucet'], ENT_QUOTES));
        global $banka_ok;
        $banka_ok = Trim(HtmlSpecialChars($_POST['banka'], ENT_QUOTES));
        global $datum_nastupu_ok;
        $datum_nastupu_ok = Trim(HtmlSpecialChars($_POST['datum_nastupu']));
        $datum_nastupu_db = date_conv_to_db("$datum_nastupu_ok");
        global $druh_pomeru_ok;
        $druh_pomeru_ok = Trim(HtmlSpecialChars($_POST['druh_pomeru']));
        global $datum_ukoncenia_ok;
        $datum_ukoncenia_ok = Trim(HtmlSpecialChars($_POST['datum_ukoncenia']));
        $datum_ukoncenia_db = date_conv_to_db("$datum_ukoncenia_ok");
        global $ostatne_ok;
        $ostatne_ok = Trim(HtmlSpecialChars($_POST['ostatne']));
        $ostatne_ok = zalamovanie_do_db("$ostatne_ok");
        global $stav_ok;
        $stav_ok = Trim(HtmlSpecialChars($_POST['stav']));
        //echo 'ok';
        if (!Empty($priezvisko_ok) && !Empty($meno_ok) && !Empty($priezvisko_rodne_ok) && ($rodne_cislo1_ok > 0) && ($rodne_cislo2_ok > 0) && !Empty($datum_narodenia_db) && !Empty($miesto_narodenia_ok) && !Empty($narodnost_ok) && !Empty($statna_prislusnost_ok) && !Empty($rodinny_stav_ok) && !Empty($poistovna_ok) && !Empty($t_ulica_ok) && !Empty($t_mesto_ok) && !Empty($t_psc_ok) && (strlen($banka_ok) > 0) && (strlen($ucet_ok) > 0) && !Empty($datum_nastupu_db) && !Empty($druh_pomeru_ok) && !Empty($stav_ok)) {
//echo 'ok';
            global $user_id, $veduci_oddelenia;
            if ($veduci_oddelenia)
                $spolid_s = "SELECT spolid FROM z WHERE id = '" . $user_id . "' ";
            else
                $spolid_s = "SELECT spolid FROM user WHERE id = '" . $user_id . "' ";
            $spolid_q = MySQL_Query($spolid_s);
            $spolid = MySQL_Fetch_Array($spolid_q);
            $akt_dat = Date("Y-m-d");
            if ($falkModeAdmin) {
                if (isset($_POST['manazer']) && ($_POST['manazer'] == 1)) {
                    $mg = 1;
                    $k = $_POST['patriK'];
                    if (isset($_POST['manazer_oddelenia'])) {
                        $mg_odd = $_POST['manazer_oddelenia'];
                    }
                } else {
                    $mg = $_POST['manazer'];
                    $k = $_POST['patriK'];
                    $mg_odd = 0;
                }
                $z_uloz_i = "INSERT INTO z (id, spolid, datum_pridania, datum_prichodu, datum_odchodu, meno, priezvisko, datum_zmeny, stavid, active, mail, ip, heslo, lang, manager, veduci_oddelenia, patri_k, pozicia, osobneCislo, costCenter, fond) VALUES (NULL, '" . $spolid['spolid'] . "', '" . $akt_dat . "', '" . $datum_nastupu_db . "', '0000-00-00', '" . $meno_ok . "', '" . $priezvisko_ok . "', '" . $akt_dat . "', '" . $stav_ok . "', 1, '', '', '', 0, " . $mg . ", " . $mg_odd . ", " . $k . ", '" . $_POST['pozicia'] . "', '" . $_POST['osobneCislo'] . "', '" . $_POST['costCenter'] . "', '" . $_POST['fond'] . "')";
            } elseif ($veduci_oddelenia != 0) {
                $kk_s = "SELECT veduci_oddelenia FROM z WHERE id = '" . $user_id . "' ";
                $kk_q = MySQL_Query($kk_s);
                $kk = MySQL_Fetch_Array($kk_q);
                $k = $kk['veduci_oddelenia'];
                $z_uloz_i = "INSERT INTO z (id, spolid, datum_pridania, datum_prichodu, datum_odchodu, meno, priezvisko, datum_zmeny, stavid, active, mail, ip, heslo, lang, manager, veduci_oddelenia, patri_k, pozicia, osobneCislo, costCenter, fond) VALUES (NULL, '" . $spolid['spolid'] . "', '" . $akt_dat . "', '" . $datum_nastupu_db . "', '0000-00-00', '" . $meno_ok . "', '" . $priezvisko_ok . "', '" . $akt_dat . "', '" . $stav_ok . "', 1, '', '', '', 0, 0, 0, " . $k . ", '" . $_POST['pozicia'] . "', '" . $_POST['osobneCislo'] . "', '" . $_POST['costCenter'] . "', '" . $_POST['fond'] . "')";
            } else {
                $z_uloz_i = "INSERT INTO z (id, spolid, datum_pridania, datum_prichodu, datum_odchodu, meno, priezvisko, datum_zmeny, stavid, active, mail, ip, heslo, lang, manager, veduci_oddelenia, patri_k) VALUES (NULL, '" . $spolid['spolid'] . "', '" . $akt_dat . "', '" . $datum_nastupu_db . "', '0000-00-00', '" . $meno_ok . "', '" . $priezvisko_ok . "', '" . $akt_dat . "', '" . $stav_ok . "', 1, '', '', '', '0', '0', '0', '0')";
            }
            //echo $z_uloz_i;
            $z_uloz_q = MySQL_Query($z_uloz_i);
            //echo "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>".$z_uloz_i;
            $zid = MySQL_Insert_ID();

            $z_meno_uloz_i = "INSERT INTO z_meno (id, meno, datum_pridania, zid) VALUES (NULL, '" . $meno_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_meno_uloz_q = MySQL_Query($z_meno_uloz_i);

            $z_priezvisko_uloz_i = "INSERT INTO z_priezvisko (id, priezvisko, datum_pridania, zid) VALUES (NULL, '" . $priezvisko_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_priezvisko_uloz_q = MySQL_Query($z_priezvisko_uloz_i);

            if (!Empty($titul_ok)) {
                $z_titul_uloz_i = "INSERT INTO z_titul (id, titul, datum_pridania, zid, active) VALUES (NULL, '" . $titul_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_titul_uloz_q = MySQL_Query($z_titul_uloz_i);
            }

            $z_priezvisko_rodne_uloz_i = "INSERT INTO z_priezvisko_rodne (id, priezvisko_rodne, datum_pridania, zid) VALUES (NULL, '" . $priezvisko_rodne_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_priezvisko_rodne_uloz_q = MySQL_Query($z_priezvisko_rodne_uloz_i);

            $z_rodne_cislo_uloz_i = "INSERT INTO z_rodne_cislo (id, cislo1, cislo2, datum_pridania, zid) VALUES (NULL, '" . $rodne_cislo1_ok . "', '" . $rodne_cislo2_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_rodne_cislo_uloz_q = MySQL_Query($z_rodne_cislo_uloz_i);

            $z_datum_narodenia_uloz_i = "INSERT INTO z_datum_narodenia (id, datum_narodenia, datum_pridania, zid) VALUES (NULL, '" . $datum_narodenia_db . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_datum_narodenia_uloz_q = MySQL_Query($z_datum_narodenia_uloz_i);

            $z_miesto_narodenia_uloz_i = "INSERT INTO z_miesto_narodenia (id, miesto, datum_pridania, zid) VALUES (NULL, '" . $miesto_narodenia_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_miesto_narodenia_uloz_q = MySQL_Query($z_miesto_narodenia_uloz_i);

            if (!Empty($tel_cislo_ok)) {
                $z_tel_cislo_uloz_i = "INSERT INTO z_tel_cislo (id, tel, datum_pridania, zid, active) VALUES (NULL, '" . $tel_cislo_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_tel_cislo_uloz_q = MySQL_Query($z_tel_cislo_uloz_i);
            }

            $z_narodnost_uloz_i = "INSERT INTO z_narodnost (id, narodnost, datum_pridania, zid) VALUES (NULL, '" . $narodnost_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_narodnost_uloz_q = MySQL_Query($z_narodnost_uloz_i);

            $z_statna_prislusnost_uloz_i = "INSERT INTO z_statna_prislusnost (id, prislusnost, datum_pridania, zid) VALUES (NULL, '" . $statna_prislusnost_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_statna_prislusnost_uloz_q = MySQL_Query($z_statna_prislusnost_uloz_i);

            if (!Empty($obciansky_preukaz_ok)) {
                $z_obciansky_preukaz_uloz_i = "INSERT INTO z_obciansky_preukaz (id, obciansky, datum_pridania, zid, active) VALUES (NULL, '" . $obciansky_preukaz_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_obciansky_preukaz_uloz_q = MySQL_Query($z_obciansky_preukaz_uloz_i);
            }

            if (!Empty($vodicsky_preukaz_ok)) {
                $z_vodicsky_preukaz_uloz_i = "INSERT INTO z_vodicsky_preukaz (id, vodicsky, datum_pridania, zid, active) VALUES (NULL, '" . $vodicsky_preukaz_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_vodicsky_preukaz_uloz_q = MySQL_Query($z_vodicsky_preukaz_uloz_i);
            }

            $z_rodinny_stav_uloz_i = "INSERT INTO z_rodinny_stav (id, stav, datum_pridania, zid) VALUES (NULL, '" . $rodinny_stav_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_rodinny_stav_uloz_q = MySQL_Query($z_rodinny_stav_uloz_i);

            if (!Empty($zdravotny_stav_ok)) {
                $z_zdravotny_stav_uloz_i = "INSERT INTO z_zdravotny_stav (id, stav, datum_pridania, zid, active) VALUES (NULL, '" . $zdravotny_stav_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_zdravotny_stav_uloz_q = MySQL_Query($z_zdravotny_stav_uloz_i);
            }

            $z_zdravotna_poistovna_uloz_i = "INSERT INTO z_zdravotna_poistovna (id, pid, datum_pridania, zid) VALUES (NULL, '" . $poistovna_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_zdravotna_poistovna_uloz_q = MySQL_Query($z_zdravotna_poistovna_uloz_i);

            $z_cislo_uctu_uloz_i = "INSERT INTO z_cislo_uctu (id, cislo0, cislo1, cislo2, datum_pridania, zid) VALUES (NULL, '" . $pred_ok . "', '" . $ucet_ok . "', '" . $banka_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_cislo_uctu_uloz_q = MySQL_Query($z_cislo_uctu_uloz_i);

            $z_druh_pomeru_uloz_i = "INSERT INTO z_druh_pomeru (id, druh, datum_pridania, zid) VALUES (NULL, '" . $druh_pomeru_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_druh_pomeru_uloz_q = MySQL_Query($z_druh_pomeru_uloz_i);

            if (!Empty($datum_ukoncenia_db)) {
                $z_datum_ukoncenia_zam_uloz_i = "INSERT INTO z_datum_ukonc_posled_zam (id, datum_ukoncenia, datum_pridania, zid, active) VALUES (NULL, '" . $datum_ukoncenia_db . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_datum_ukoncenia_zam_uloz_q = MySQL_Query($z_datum_ukoncenia_zam_uloz_i);
            }

            if (!Empty($ostatne_ok)) {
                $z_ostatne_uloz_i = "INSERT INTO z_ostatne (id, ostatne, datum_pridania, zid, active) VALUES (NULL, '" . $ostatne_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_ostatne_uloz_q = MySQL_Query($z_ostatne_uloz_i);
            }

            $z_bydlisko_trvale_uloz_i = "INSERT INTO z_bydlisko_trvale (id, ulica, psc, mesto, tel, datum_pridania, zid) VALUES (NULL, '" . $t_ulica_ok . "', '" . $t_psc_ok . "', '" . $t_mesto_ok . "', '" . $t_tel_ok . "', '" . $akt_dat . "', '" . $zid . "')";
            $z_bydlisko_trvale_uloz_q = MySQL_Query($z_bydlisko_trvale_uloz_i);

            if (!Empty($ostatne_ok)) {
                $z_bydlisko_prechodne_uloz_i = "INSERT INTO z_bydlisko_prechodne (id, ulica, psc, mesto, tel, datum_pridania, zid, active) VALUES (NULL, '" . $p_ulica_ok . "', '" . $p_psc_ok . "', '" . $p_mesto_ok . "', '" . $p_tel_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $z_bydlisko_prechodne_uloz_q = MySQL_Query($z_bydlisko_prechodne_uloz_i);
            }

            form_viac_suborov_ulozit("$zid");

            $starost_s = "SELECT spolocnost.nazov,spolocnost.uid,user.mail FROM spolocnost,user WHERE spolocnost.id = '" . $spolid['spolid'] . "' AND user.id = spolocnost.uid ";
            $starost_q = MySQL_Query($starost_s);
            $starost = MySQL_Fetch_Array($starost_q);
            $komu = $starost['mail'];
            $predmet = "mzdy.bmbleitner.sk";
            $text = "Spoločnosť " . $starost['nazov'] . " pridala nového zamestnanca: " . $priezvisko_ok . " " . $meno_ok;

            poslat_email($komu, $predmet, $text);

            Header("Location: home.php?akc=3");
            exit();
        } else {
            $vypis = preklad(54);
        }
    }
}

function form_viac_suborov($poc_subor) {
    $ret = "<div style=\"padding:5px;margin:5px;background:#eee;\">
<input type=\"file\" name=\"subor\" id=\"my_file_element\" />
<div id=\"files_list\" style=\"border:1px solid black;padding:5px;background:#fff;font-size:x-small;\"><strong>" . preklad(55) . " (" . preklad(56) . " " . $poc_subor . "):</strong></div>
<script>
	var multi_selector = new MultiSelector( document.getElementById( 'files_list' ), " . $poc_subor . " );
	multi_selector.addElement( document.getElementById( 'my_file_element' ) );
</script>
</div>\n";
    return $ret;
}

function form_viac_suborov_ulozit($zid) {
    if (!Empty($_FILES['subor']['name'])) {
        $i = 1;
        while (list($key, $value) = each($_FILES['subor']['name'])) {
            if (!Empty($value)) {
                $filename = Trim(HtmlSpecialChars($value));
                $filename = Str_Replace(" ", "_", $filename);
                $ftp = "document_zam_" . $zid . "_" . MD5(MicroTime()) . "_" . $i;
                $document = $_FILES['subor']['tmp_name'][$key];
                $type = ($_FILES['subor']['type'][$key]);
                @mkdir($document, 0777);
                @chmod($document, 0777);
                if (Move_Uploaded_File($document, DOCS_ADDRESS . $ftp)) {
                    global $user_id;
                    $len_s = "SELECT admin FROM user WHERE id = '" . $user_id . "' ";
                    $len_q = MySQL_Query($len_s);
                    $len = MySQL_Fetch_Array($len_q);
                    $akt_dat = Date("Y-m-d");
                    $uloz_i = "INSERT INTO z_docs (id, nazov, ftp, type, datum_pridania, datum_spracovania, zid, len_admin, spracovat, active) VALUES (NULL, '" . $filename . "', '" . $ftp . "', '" . $type . "', '" . $akt_dat . "', '0000-00-00', '" . $zid . "', '" . $len['admin'] . "', 1, 1)";
                    $uloz_q = MySQL_Query($uloz_i);
                }
                $i++;
            }
        }
    }
}

function docs_size($ftp) {
    if (file_exists(DOCS_ADDRESS . $ftp)) {
        $file_size = filesize(DOCS_ADDRESS . $ftp);
        if (floor($file_size / (1024 * 1024)))
            $text = round($file_size / (1024 * 1024), 2) . ' MB';
        elseif (floor($file_size / 1024))
            $text = round($file_size / 1024, 2) . ' kB';
        else
            $text = $file_size . ' B';
    }
    else
        $text = '';
    return $text;
}

function zoznam_docs_zam($zid) {
    global $user_id;
    $len_s = "SELECT admin FROM user WHERE id = '" . $user_id . "' ";
    $len_q = MySQL_Query($len_s);
    $len = MySQL_Fetch_Array($len_q);
    $docs_s = "SELECT * FROM z_docs WHERE zid = '" . $zid . "' AND len_admin <= '" . $len['admin'] . "' ORDER BY nazov ASC";
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    if ($docs_n > 0) {
        $i = 1;
        $ret = "<table>";
        $ret .= "<tr><td>#</td><td>" . preklad(66) . "</td><td>" . preklad(67) . "</td></tr>";
        while ($docs = MySQL_Fetch_Array($docs_q)) {
            $ret .= "<tr><td>" . $i . "</td><td><a href=\"get_file.php?did=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td></tr>";
            $i++;
        }
        $ret .= "</table>";
    } else {
        $ret = preklad(65);
    }
    return $ret;
}

function profil_zamestnanec_spol($zid, $falkModeAdmin = false) {
    global $veduci_oddelenia;
    echo "<h2>" . preklad(57) . "</h2>\n";
    $povol = pristup_zid("$zid");
    if ($povol == 1) {
        echo "<table width=\"100%\">\n";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(19) . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_meno WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(21) . "</td><td class=\"vypis_tab_main\">" . $nac['meno'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(20) . "</td><td class=\"vypis_tab_main\">" . $nac['priezvisko'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_titul WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['titul']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(22) . "</td><td class=\"vypis_tab_main\">" . $nac['titul'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko_rodne WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(23) . "</td><td class=\"vypis_tab_main\">" . $nac['priezvisko_rodne'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodne_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(24) . "</td><td class=\"vypis_tab_main\">" . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nar = date_conv_to_view($nac['datum_narodenia']);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(25) . "</td><td class=\"vypis_tab_main\">" . $dat_nar . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_miesto_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(26) . "</td><td class=\"vypis_tab_main\">" . $nac['miesto'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_tel_cislo WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['tel']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(27) . "</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_narodnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(28) . "</td><td class=\"vypis_tab_main\">" . $nac['narodnost'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_statna_prislusnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(29) . "</td><td class=\"vypis_tab_main\">" . $nac['prislusnost'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_obciansky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['obciansky']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(30) . "</td><td class=\"vypis_tab_main\">" . $nac['obciansky'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_vodicsky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['vodicsky']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(31) . "</td><td class=\"vypis_tab_main\">" . $nac['vodicsky'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodinny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(32) . "</td><td class=\"vypis_tab_main\">" . $nac['stav'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotny_stav WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['stav']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(33) . "</td><td class=\"vypis_tab_main\">" . $nac['stav'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT z_zdravotna_poistovna.pid,poistovna.nazov,DATE_FORMAT(z_zdravotna_poistovna.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotna_poistovna,poistovna WHERE z_zdravotna_poistovna.zid = '" . $zid . "' AND poistovna.id = z_zdravotna_poistovna.pid ORDER BY z_zdravotna_poistovna.id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(34) . "</td><td class=\"vypis_tab_main\">" . $nac['nazov'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_trvale WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(35) . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(58) . "</td><td class=\"vypis_tab_main\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td>&nbsp;</td></tr>";
        if (!Empty($nac['tel']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(39) . "</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";



        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_prechodne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['ulica'])) {
            echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
            echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(40) . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(58) . "</td><td class=\"vypis_tab_main\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td>&nbsp;</td></tr>";
            if (!Empty($nac['tel']))
                echo "<tr><td class=\"vypis_tab_left\">" . preklad(39) . "</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";
        }


        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(z_cislo_uctu.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_cislo_uctu,banka WHERE z_cislo_uctu.zid = '" . $zid . "' AND banka.kod = z_cislo_uctu.cislo2 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(41) . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(59) . "</td><td class=\"vypis_tab_main\">" . $nac['nazov'] . "</td><td>&nbsp;</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(61) . "</td><td class=\"vypis_tab_main\">" . (($nac['cislo0'] > 0) ? $nac['cislo0'] . "-" : "") . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td>&nbsp;</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(44) . "</td></tr>";

        $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nastup = date_conv_to_view($nac['datum_prichodu']);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(45) . "</td><td class=\"vypis_tab_main\">" . $dat_nastup . "</td><td>&nbsp;</td></tr>";
        $dat_odchod = date_conv_to_view($nac['datum_odchodu']);
        if ($dat_odchod > "00.00.0000")
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(62) . "</td><td class=\"vypis_tab_main\">" . $dat_odchod . "</td><td>&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_druh_pomeru WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(46) . "</td><td class=\"vypis_tab_main\">" . $nac['druh'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_ukonc_posled_zam WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_ukonc = date_conv_to_view($nac['datum_ukoncenia']);
        if (!Empty($nac['datum_ukoncenia']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(47) . "</td><td class=\"vypis_tab_main\">" . $dat_ukonc . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_ostatne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['ostatne']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(48) . "</td><td>" . $nac['ostatne'] . "</td><td class=\"vypis_tab_main\"> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT stav.stav,stav.jazyk_id FROM z,stav WHERE z.id = '" . $zid . "' AND stav.id = z.stavid ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(49) . "</td><td>" . preklad($nac['jazyk_id']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        if ($falkModeAdmin) {
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $odpoved = array(preklad(146), preklad(140), preklad(158));
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(157) . "</td><td>" . $odpoved[$nac['manager']] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            if ($nac['manager']) {
                echo "<tr><td class=\"vypis_tab_left\">" . preklad(139) . "</td><td>";
                $nacc_s = "SELECT nazov FROM oddelenie WHERE id = '" . $nac['veduci_oddelenia'] . "'";
                $nacc_q = MySQL_Query($nacc_s);
                $nacc = MySQL_Fetch_Array($nacc_q);
                echo $nacc['nazov'];
                echo "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            }
            $nacc_s = "SELECT nazov FROM oddelenie WHERE id = '" . $nac['patri_k'] . "'";
            $nacc_q = MySQL_Query($nacc_s);
            $nacc = MySQL_Fetch_Array($nacc_q);
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(141) . "</td><td>" . $nacc['nazov'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(148) . "</td><td>" . ($nac['pozicia']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(149) . "</td><td>" . ($nac['osobneCislo']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(150) . "</td><td>" . ($nac['costCenter']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(151) . "</td><td>" . ($nac['fond']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
        } elseif ($veduci_oddelenia != 0) {
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(148) . "</td><td>" . ($nac['pozicia']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(149) . "</td><td>" . ($nac['osobneCislo']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(150) . "</td><td>" . ($nac['costCenter']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(151) . "</td><td>" . ($nac['fond']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
        }

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(55) . "</td></tr>";

        echo "<tr><td colspan=\"2\">" . zoznam_docs_zam($zid) . "</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" style=\"font-weight: bold;\"><a href=\"?akc=3&akc2=3&zid=" . $zid . "\">" . preklad(63) . "</a> | <a href=\"?akc=3&akc2=4&zid=" . $zid . "\">" . preklad(17) . "</a></td></tr>";

        echo "</table>\n";
    } else {
        echo "takýto zamestnanec neexistuje!";
    }
}

function profil_zamestnanec_spol2($zid, $falkModeAdmin=false) {
    global $veduci_oddelenia;
    echo "<h2>" . preklad(68) . "</h2>\n";
    $povol = pristup_zid("$zid");
    if ($povol == 1) {
        echo "<table width=\"100%\">\n";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(19) . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_meno WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(21) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['meno'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(20) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['priezvisko'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_titul WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(22) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['titul'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko_rodne WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(23) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['priezvisko_rodne'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodne_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(24) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            $dat_nar = date_conv_to_view($nac['datum_narodenia']);
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(25) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $dat_nar . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_miesto_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(26) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['miesto'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_tel_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(27) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['tel'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_narodnost WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(22) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['narodnost'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_statna_prislusnost WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(29) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['prislusnost'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_obciansky_preukaz WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(30) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['obciansky'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_vodicsky_preukaz WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(31) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['vodicsky'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodinny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(32) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['stav'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(33) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['stav'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT z_zdravotna_poistovna.pid,poistovna.nazov,DATE_FORMAT(z_zdravotna_poistovna.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotna_poistovna,poistovna WHERE z_zdravotna_poistovna.zid = '" . $zid . "' AND poistovna.id = z_zdravotna_poistovna.pid ORDER BY z_zdravotna_poistovna.id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(34) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['nazov'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_trvale WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            if ($i == 1)
                echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(35) . "</td><td>&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(58) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            if (!Empty($nac['tel']))
                echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(39) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";
            $i++;
        }


        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_prechodne WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            if ($i == 1) {
                echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
                echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(40) . "</td><td>&nbsp;</td></tr>";
            }
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(58) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            if (!Empty($nac['tel']))
                echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(39) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";
            $i++;
        }


        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(z_cislo_uctu.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_cislo_uctu,banka WHERE z_cislo_uctu.zid = '" . $zid . "' AND banka.kod = z_cislo_uctu.cislo2 ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            if ($i == 1)
                echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(41) . "</td><td>&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(59) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['nazov'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(61) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . (($nac['cislo0'] > 0) ? $nac['cislo0'] . "-" : "") . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td>&nbsp;</td></tr>";
            $i++;
        }

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(44) . "</td></tr>";

        $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nastup = date_conv_to_view($nac['datum_prichodu']);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(45) . "</td><td class=\"vypis_tab_main\">" . $dat_nastup . "</td><td>&nbsp;</td></tr>";
        $dat_odchod = date_conv_to_view($nac['datum_odchodu']);
        if ($dat_odchod > "00.00.0000")
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(62) . "</td><td class=\"vypis_tab_main\">" . $dat_odchod . "</td><td>&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_druh_pomeru WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(46) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['druh'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_ukonc_posled_zam WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            $dat_ukonc = date_conv_to_view($nac['datum_ukoncenia']);
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(47) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $dat_ukonc . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_ostatne WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? preklad(48) : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['ostatne'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT stav.stav,stav.jazyk_id FROM z,stav WHERE z.id = '" . $zid . "' AND stav.id = z.stavid ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(49) . "</td><td>" . preklad($nac['jazyk_id']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        if ($falkModeAdmin) {
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $odpoved = array(preklad(146), preklad(140), preklad(158));
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(157) . "</td><td>" . $odpoved[$nac['manager']] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            if ($nac['manager']) {
                echo "<tr><td class=\"vypis_tab_left\">" . preklad(139) . "</td><td>";
                $nacc_s = "SELECT nazov FROM oddelenie WHERE id = '" . $nac['veduci_oddelenia'] . "'";
                $nacc_q = MySQL_Query($nacc_s);
                $nacc = MySQL_Fetch_Array($nacc_q);
                echo $nacc['nazov'];
                echo "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            }
            $nacc_s = "SELECT nazov FROM oddelenie WHERE id = '" . $nac['patri_k'] . "'";
            $nacc_q = MySQL_Query($nacc_s);
            $nacc = MySQL_Fetch_Array($nacc_q);
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(141) . "</td><td>" . $nacc['nazov'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(148) . "</td><td>" . ($nac['pozicia']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(149) . "</td><td>" . ($nac['osobneCislo']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(150) . "</td><td>" . ($nac['costCenter']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(151) . "</td><td>" . ($nac['fond']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
        } elseif ($veduci_oddelenia != 0) {
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(148) . "</td><td>" . ($nac['pozicia']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(149) . "</td><td>" . ($nac['osobneCislo']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(150) . "</td><td>" . ($nac['costCenter']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(151) . "</td><td>" . ($nac['fond']) . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
        }

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(55) . "</td></tr>";

        echo "<tr><td colspan=\"3\">" . zoznam_docs_zam($zid) . "</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" style=\"font-weight: bold;\"><a href=\"?akc=3&akc2=2&zid=" . $zid . "\">" . preklad(69) . "</a> | <a href=\"?akc=3&akc2=4&zid=" . $zid . "\">" . preklad(17) . "</a></td></tr>";

        echo "</table>\n";
    } else {
        echo "takýto zamestnanec neexistuje!";
    }
}

function profil_zamestnanec_spol3($zid, $falkModeAdmin=false) {
    global $veduci_oddelenia;
    echo "<h2>" . preklad(73) . "</h2>\n";
    $povol = pristup_zid("$zid");
    if ($povol == 1) {
        $nevyplnene = "<font class=\"gray\">" . preklad(72) . "</font>";
        echo "<form action=\"home.php?akc=3&akc2=4&zid=" . $zid . "\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\">\n";
        echo "<table width=\"100%\">\n";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(19) . "</td></tr>";

        $nac_s = "SELECT * FROM z_meno WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(21) . "</td><td class=\"vypis_tab_main\">" . $nac['meno'] . "</td><td> " . uprava_link($nac['meno'], 1, 1, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_priezvisko WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(20) . "</td><td class=\"vypis_tab_main\">" . $nac['priezvisko'] . "</td><td> " . uprava_link($nac['priezvisko'], 1, 2, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_titul WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(22) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['titul'])) ? $nac['titul'] : $nevyplnene) . "</td><td> " . uprava_link($nac['titul'], 0, 3, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_priezvisko_rodne WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(23) . "</td><td class=\"vypis_tab_main\">" . $nac['priezvisko_rodne'] . "</td><td> " . uprava_link($nac['priezvisko_rodne'], 1, 4, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_rodne_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(24) . "</td><td class=\"vypis_tab_main\">" . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td> " . uprava_link($nac['cislo1'], 1, 5, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_datum_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nar = date_conv_to_view($nac['datum_narodenia']);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(25) . "</td><td class=\"vypis_tab_main\">" . $dat_nar . "</td><td> " . uprava_link($dat_nar, 1, 6, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_miesto_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(26) . "</td><td class=\"vypis_tab_main\">" . $nac['miesto'] . "</td><td> " . uprava_link($nac['miesto'], 1, 7, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_tel_cislo WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(27) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['tel'])) ? $nac['tel'] : $nevyplnene) . "</td><td> " . uprava_link($nac['tel'], 2, 8, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_narodnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(28) . "</td><td class=\"vypis_tab_main\">" . $nac['narodnost'] . "</td><td> " . uprava_link($nac['narodnost'], 1, 9, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_statna_prislusnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(29) . "</td><td class=\"vypis_tab_main\">" . $nac['prislusnost'] . "</td><td> " . uprava_link($nac['prislusnost'], 1, 10, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_obciansky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(30) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['obciansky'])) ? $nac['obciansky'] : $nevyplnene) . "</td><td> " . uprava_link($nac['obciansky'], 2, 11, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_vodicsky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(31) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['vodicsky'])) ? $nac['vodicsky'] : $nevyplnene) . "</td><td> " . uprava_link($nac['vodicsky'], 2, 12, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_rodinny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(32) . "</td><td class=\"vypis_tab_main\">" . $nac['stav'] . "</td><td> " . uprava_link($nac['stav'], 1, 13, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_zdravotny_stav WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(33) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['stav'])) ? $nac['stav'] : $nevyplnene) . "</td><td>  " . uprava_link($nac['stav'], 2, 14, $zid) . "</td></tr>";

        $nac_s = "SELECT z_zdravotna_poistovna.pid,poistovna.nazov FROM z_zdravotna_poistovna,poistovna WHERE z_zdravotna_poistovna.zid = '" . $zid . "' AND poistovna.id = z_zdravotna_poistovna.pid ORDER BY z_zdravotna_poistovna.id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(34) . "</td><td class=\"vypis_tab_main\">" . $nac['nazov'] . "</td><td> " . uprava_link($nac['poistovna'], 1, 15, $zid) . "</td></tr>";

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT * FROM z_bydlisko_trvale WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(35) . "</td><td>&nbsp;</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(58) . "</td><td class=\"vypis_tab_main\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td> " . uprava_link($nac['ulica'], 1, 16, $zid) . "</td></tr>";
        if (!Empty($nac['tel']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(39) . "</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";


        $nac_s = "SELECT * FROM z_bydlisko_prechodne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(40) . "</td><td>&nbsp;</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(58) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['ulica'])) ? $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] : $nevyplnene) . "</td><td> " . uprava_link($nac['ulica'], 2, 17, $zid) . "</td></tr>";
        if (!Empty($nac['tel']))
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(39) . "</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";


        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT * FROM z_cislo_uctu,banka WHERE z_cislo_uctu.zid = '" . $zid . "' AND banka.kod = z_cislo_uctu.cislo2 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(41) . "</td><td>&nbsp;</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(59) . "</td><td class=\"vypis_tab_main\">" . $nac['nazov'] . "</td><td> " . uprava_link($nac['cislo1'], 1, 18, $zid) . "</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(61) . "</td><td class=\"vypis_tab_main\">" . (($nac['cislo0'] > 0) ? $nac['cislo0'] . "-" : "") . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td>&nbsp;</td></tr>";

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(44) . "</td></tr>";

        $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nastup = date_conv_to_view($nac['datum_prichodu']);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(45) . "</td><td class=\"vypis_tab_main\">" . $dat_nastup . "</td><td> " . uprava_link($dat_nastup, 1, 19, $zid) . "</td></tr>";
        $dat_odchod = date_conv_to_view($nac['datum_odchodu']);
        if ($dat_odchod > "00.00.0000")
            $ci_vypln = 1;
        else
            $ci_vypln = "";
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(62) . "</td><td class=\"vypis_tab_main\">" . (($dat_odchod > "00.00.0000") ? $dat_odchod : $nevyplnene) . "</td><td> " . uprava_link($ci_vypln, 2, 20, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_druh_pomeru WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(46) . "</td><td class=\"vypis_tab_main\">" . $nac['druh'] . "</td><td> " . uprava_link($nac['druh'], 1, 21, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_datum_ukonc_posled_zam WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_ukonc = date_conv_to_view($nac['datum_ukoncenia']);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(47) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['datum_ukoncenia'])) ? $dat_ukonc : $nevyplnene) . "</td><td> " . uprava_link($nac['datum_ukoncenia'], 2, 22, $zid) . "</td></tr>";

        $nac_s = "SELECT * FROM z_ostatne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(48) . "</td><td>" . ((!Empty($nac['ostatne'])) ? $nac['ostatne'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\"> " . uprava_link($nac['ostatne'], 2, 23, $zid) . "</td></tr>";

        $nac_s = "SELECT stav.stav,stav.jazyk_id FROM z,stav WHERE z.id = '" . $zid . "' AND stav.id = z.stavid ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(49) . "</td><td>" . preklad($nac['jazyk_id']) . "</td><td class=\"vypis_tab_main\"> " . uprava_link($nac['druh'], 1, 24, $zid) . "</td></tr>";
        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        if ($falkModeAdmin) {
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $odpoved = array(preklad(146), preklad(140), preklad(158));
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(157) . "</td><td>" . $odpoved[$nac['manager']] . "</td><td rowspan=\"3\" class=\"vypis_tab_main\">" . uprava_link($nac['manager'], 1, 88, $zid) . "</td></tr>";
            if ($nac['manager']) {
                echo "<tr><td class=\"vypis_tab_left\">" . preklad(139) . "</td><td>";
                $nacc_s = "SELECT nazov FROM oddelenie WHERE id = '" . $nac['veduci_oddelenia'] . "'";
                $nacc_q = MySQL_Query($nacc_s);
                $nacc = MySQL_Fetch_Array($nacc_q);
                echo $nacc['nazov'];
                echo "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            } else {
                echo "<tr><td class=\"vypis_tab_left\">&nbsp;</td><td>";
                echo "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            }
            $nacc_s = "SELECT nazov FROM oddelenie WHERE id = '" . $nac['patri_k'] . "'";
            $nacc_q = MySQL_Query($nacc_s);
            $nacc = MySQL_Fetch_Array($nacc_q);
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(141) . "</td><td>" . $nacc['nazov'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(148) . "</td><td>" . ((!Empty($nac['pozicia'])) ? $nac['pozicia'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['pozicia'], 2, 101, $zid) . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(149) . "</td><td>" . ((!Empty($nac['osobneCislo'])) ? $nac['osobneCislo'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['osobneCislo'], 2, 102, $zid) . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(150) . "</td><td>" . ((!Empty($nac['costCenter'])) ? $nac['costCenter'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['costCenter'], 2, 103, $zid) . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(151) . "</td><td>" . ((trim($nac['fond']) != '') ? $nac['fond'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['fond'], 2, 104, $zid) . "</td></tr>";
        } elseif ($veduci_oddelenia != 0) {
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(148) . "</td><td>" . ((!Empty($nac['pozicia'])) ? $nac['pozicia'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['pozicia'], 2, 101, $zid) . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(149) . "</td><td>" . ((!Empty($nac['osobneCislo'])) ? $nac['osobneCislo'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['osobneCislo'], 2, 102, $zid) . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(150) . "</td><td>" . ((!Empty($nac['costCenter'])) ? $nac['costCenter'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['costCenter'], 2, 103, $zid) . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . preklad(151) . "</td><td>" . ((trim($nac['fond']) != '') ? $nac['fond'] : $nevyplnene) . "</td><td class=\"vypis_tab_main\">" . uprava_link($nac['fond'], 2, 104, $zid) . "</td></tr>";
        }

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT mail,ip,heslo FROM z WHERE id = '" . $zid . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">" . preklad(126) . "</td><td class=\"vypis_tab_main\">" . ((!Empty($nac['mail'])) ? $nac['mail'] : $nevyplnene) . "</td><td>  " . uprava_link($nac['stav'], 1, 25, $zid) . "</td></tr>";

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">" . preklad(55) . "</td></tr>";

        echo "<tr><td colspan=\"3\">" . zoznam_docs_zam($zid) . "</td></tr>";
        echo "<tr><td colspan=\"3\">" . form_viac_suborov(5) . "</td></tr>\n";
        echo "<tr><td colspan=\"3\"><input type=\"hidden\" name=\"uloz_zam_spol_3\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" /> <a href=\"?akc=3&akc2=2&zid=" . $zid . "\">" . preklad(69) . "</a> | <a href=\"?akc=3&akc2=3&zid=" . $zid . "\">" . preklad(63) . "</a></td></tr>\n";
        echo "</table>\n";
        echo "</form>";
    } else {
        echo "takýto zamestnanec neexistuje!";
    }
}

function profil_zamestnanec_spol3_uloz() {
    $zid = IntVal($_GET['zid']);
    form_viac_suborov_ulozit("$zid");
    last_update_z("$zid");
    Header("Location: home.php?akc=3&akc2=4&zid=$zid");
    exit();
}

function last_update_z($zid) {
    $akt_dat = Date("Y-m-d");
    $up_u = "UPDATE z SET datum_zmeny = '" . $akt_dat . "' WHERE id = '" . $zid . "' ";
    $up_q = MySQL_Query($up_u);
}

function uprava_link($vypln, $povinne, $co, $zid) {
    if ($povinne == 1) {
        $ret = "<a href=\"home.php?akc=3&akc2=4&uprava=" . $co . "&zid=" . $zid . "\">" . preklad(17) . "</a>";
    } else {
        if (!Empty($vypln))
            $ret = "<a href=\"home.php?akc=3&akc2=4&neaktual=" . $co . "&zid=" . $zid . "\">" . preklad(64) . "</a> | ";
        $ret .= "<a href=\"home.php?akc=3&akc2=4&uprava=" . $co . "&zid=" . $zid . "\">" . preklad(17) . "</a>";
    }
    return $ret;
}

function profil_zamestnanec_spol3_uprava($zid, $uprava, $falkModeAdmin= false) {
    echo "<h2>Úprava zamestnanca</h2>\n";
    $upravaManagera = false;
    $povol = pristup_zid("$zid");
    if ($povol == 1) {
        if ($uprava == 1) {
            $nazov = preklad(21);
            $nac_s = "SELECT * FROM z_meno WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['meno'];
            $policka = "<input type=\"text\" name=\"meno\" />";
            $over_toto[] = "meno,Meno";
        } elseif ($uprava == 2) {
            $nazov = preklad(20);
            $nac_s = "SELECT * FROM z_priezvisko WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['priezvisko'];
            $policka = "<input type=\"text\" name=\"priezvisko\" />";
            $over_toto[] = "priezvisko,Priezvisko";
        } elseif ($uprava == 3) {
            $nazov = preklad(22);
            $nac_s = "SELECT * FROM z_titul WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['titul'];
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"titul\" />";
            $over_toto[] = "titul,Titul";
        }
        elseif ($uprava == 4) {
            $nazov = preklad(23);
            $nac_s = "SELECT * FROM z_priezvisko_rodne WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['priezvisko_rodne'];
            $policka = "<input type=\"text\" name=\"priezvisko_rodne\" />";
            $over_toto[] = "priezvisko_rodne,Rodné priezvisko";
        } elseif ($uprava == 5) {
            $nazov = preklad(24);
            $nac_s = "SELECT * FROM z_rodne_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['cislo1'] . "/" . $nac['cislo2'];
            $policka = "<input type=\"text\" name=\"rodne_cislo1\" maxlength=\"6\" /> / <input type=\"text\" name=\"rodne_cislo2\" maxlength=\"4\" />";
            $over_toto[] = "rodne_cislo1,Rodné číslo";
            $over_toto[] = "rodne_cislo2,Rodné číslo";
        } elseif ($uprava == 6) {
            $nazov = preklad(25);
            $nac_s = "SELECT * FROM z_datum_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $dat_nar = date_conv_to_view($nac['datum_narodenia']);
            $povod_hodn = $dat_nar;
            $policka = "<input type=\"text\" name=\"datum_narodenia\" id=\"datum_narodenia\" /> <a href=\"javascript:NewCssCal('datum_narodenia','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a>";
            $over_toto[] = "datum_narodenia,Dátum narodenia";
        } elseif ($uprava == 7) {
            $nazov = preklad(26);
            $nac_s = "SELECT * FROM z_miesto_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['miesto'];
            $policka = "<input type=\"text\" name=\"miesto_narodenia\" />";
            $over_toto[] = "miesto_narodenia,Miesto narodenia";
        } elseif ($uprava == 8) {
            $nazov = preklad(27);
            $nac_s = "SELECT * FROM z_tel_cislo WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['tel'];
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"tel_cislo\" />";
            $over_toto[] = "tel_cislo,Tel. číslo";
        }
        elseif ($uprava == 9) {
            $nazov = preklad(28);
            $nac_s = "SELECT * FROM z_narodnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['narodnost'];
            $policka = "<input type=\"text\" name=\"narodnost\" />";
            $over_toto[] = "narodnost,Národnosť";
        } elseif ($uprava == 10) {
            $nazov = preklad(29);
            $nac_s = "SELECT * FROM z_statna_prislusnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['prislusnost'];
            $policka = "<input type=\"text\" name=\"statna_prislusnost\" />";
            $over_toto[] = "statna_prislusnost,Štátna príslušnosť";
        } elseif ($uprava == 11) {
            $nazov = preklad(30);
            $nac_s = "SELECT * FROM z_obciansky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['obciansky'];
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"obciansky_preukaz\" />";
            $over_toto[] = "obciansky_preukaz,Číslo občianskeho preukazu";
        }
        elseif ($uprava == 12) {
            $nazov = preklad(31);
            $nac_s = "SELECT * FROM z_vodicsky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['vodicsky'];
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"vodicsky_preukaz\" />";
            $over_toto[] = "vodicsky_preukaz,Vodičský preukaz";
        }
        elseif ($uprava == 13) {
            $nazov = preklad(32);
            $nac_s = "SELECT * FROM z_rodinny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['stav'];
            $policka = "<input type=\"text\" name=\"rodinny_stav\" />";
            $over_toto[] = "rodinny_stav,Rodinný stav";
        } elseif ($uprava == 14) {
            $nazov = preklad(33);
            $nac_s = "SELECT * FROM z_zdravotny_stav WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['stav'];
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"zdravotny_stav\" />";
            $over_toto[] = "zdravotny_stav,Zdravotný stav";
        }
        elseif ($uprava == 15) {
            $nazov = preklad(34);
            $nac_s = "SELECT z_zdravotna_poistovna.pid,poistovna.nazov FROM z_zdravotna_poistovna,poistovna WHERE z_zdravotna_poistovna.zid = '" . $zid . "' AND poistovna.id = z_zdravotna_poistovna.pid ORDER BY z_zdravotna_poistovna.id DESC LIMIT 0,1";
            //$nac_s = "SELECT * FROM z_zdravotna_poistovna WHERE zid = '".$zid."' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['nazov'];
            $policka = "<select name=\"poistovna\"><option value=\"\">" . preklad(50) . "</option>";
            $poistovne_s = "SELECT * FROM poistovna ORDER BY nazov ASC";
            $poistovne_q = MySQL_Query($poistovne_s);
            while ($poistovne = MySQL_Fetch_Array($poistovne_q)) {
                $policka .= "<option value=\"" . $poistovne['id'] . "\">" . $poistovne['nazov'] . "</option>";
            }
            $policka .= "</select>\n";
            $over_toto[] = "poistovna,Zdravotná poistovna";
        } elseif ($uprava == 16) {
            $nazov = preklad(35);
            $nac_s = "SELECT * FROM z_bydlisko_trvale WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . ((!Empty($nac['tel'])) ? ", " . $nac['tel'] : "" );
            $policka = "<table>";
            $policka .= "<tr><td><b>" . preklad(36) . "</b></td><td><input type=\"text\" name=\"t_ulica\" /></td></tr>\n";
            $policka .= "<tr><td><b>" . preklad(37) . "</b></td><td><input type=\"text\" name=\"t_mesto\" /></td></tr>\n";
            $policka .= "<tr><td><b>" . preklad(38) . "</b></td><td><input type=\"text\" name=\"t_psc\" /></td></tr>\n";
            $policka .= "<tr><td>" . preklad(39) . "</td><td><input type=\"text\" name=\"t_tel\" /></td></tr>\n";
            $policka .= "</table>";
            $over_toto[] = "t_ulica,Ulica";
            $over_toto[] = "t_mesto,Mesto/obec";
            $over_toto[] = "t_psc,PSČ";
        } elseif ($uprava == 17) {
            $nazov = preklad(40);
            $nac_s = "SELECT * FROM z_bydlisko_prechodne WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            if (!Empty($nac['ulica']))
                $povod_hodn = $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . ((!Empty($nac['tel'])) ? ", " . $nac['tel'] : "" );
            else
                $povod_hodn = "";
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<table>";
            $policka .= "<tr><td><b>" . preklad(36) . "</b></td><td><input type=\"text\" name=\"p_ulica\" /></td></tr>\n";
            $policka .= "<tr><td><b>" . preklad(37) . "</b></td><td><input type=\"text\" name=\"p_mesto\" /></td></tr>\n";
            $policka .= "<tr><td><b>" . preklad(38) . "</b></td><td><input type=\"text\" name=\"p_psc\" /></td></tr>\n";
            $policka .= "<tr><td>" . preklad(39) . "</td><td><input type=\"text\" name=\"p_tel\" /></td></tr>\n";
            $policka .= "</table>";
            $over_toto[] = "p_ulica,Ulica";
            $over_toto[] = "p_mesto,Mesto/obec";
            $over_toto[] = "p_psc,PSČ";
        }
        elseif ($uprava == 18) {
            $nazov = preklad(42) . " - " . preklad(43);
            $nac_s = "SELECT * FROM z_cislo_uctu,banka WHERE z_cislo_uctu.zid = '" . $zid . "' AND banka.kod = z_cislo_uctu.cislo2 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = (($nac['cislo0'] > 0) ? $nac['cislo0'] . "-" : "") . $nac['cislo1'] . "/" . $nac['cislo2'];
            $policka = "<input type=\"text\" name=\"pred\" maxlength=\"6\" /> - <input type=\"text\" name=\"ucet\" maxlength=\"10\" /> / <select name=\"banka\"><option value=\"\">" . preklad(50) . "</option>";
            $banky_s = "SELECT * FROM banka ORDER BY kod ASC";
            $banky_q = MySQL_Query($banky_s);
            while ($banky = MySQL_Fetch_Array($banky_q)) {
                $policka .= "<option value=\"" . $banky['kod'] . "\">" . $banky['kod'] . " - " . $banky['nazov'] . "</option>";
            }
            $policka .= "</select>\n";
            $over_toto[] = "banka,Názov banky";
            $over_toto[] = "ucet,Číslo účtu";
        } elseif ($uprava == 19) {
            $nazov = preklad(45);
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $dat_nastup = date_conv_to_view($nac['datum_prichodu']);
            $povod_hodn = $dat_nastup;
            $policka = "<input type=\"text\" name=\"datum_nastupu\" id=\"datum_nastupu\" readonly /> <a href=\"javascript:NewCssCal('datum_nastupu','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a>";
            $over_toto[] = "datum_nastupu,Dátum nástupu do zamestnania";
        } elseif ($uprava == 20) {
            $nazov = preklad(62);
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $dat_odchod = date_conv_to_view($nac['datum_odchodu']);
            if ($dat_odchod > "00.00.0000")
                $povod_hodn = $dat_odchod;
            else
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"datum_vypovede\" id=\"datum_vypovede\" readonly /> <a href=\"javascript:NewCssCal('datum_vypovede','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a>";
            $over_toto[] = "datum_vypovede,Dátum skončenia pracovného pomeru";
        }
        elseif ($uprava == 21) {
            $nazov = preklad(46);
            $nac_s = "SELECT * FROM z_druh_pomeru WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['druh'];
            $policka = "<input type=\"text\" name=\"druh_pomeru\" />";
            $over_toto[] = "druh_pomeru,Druh pracovného pomeru";
        } elseif ($uprava == 101) {
            $nazov = preklad(148);
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['pozicia'];
            $policka = "<input type=\"text\" name=\"pozicia\" />";
        } elseif ($uprava == 102) {
            $nazov = preklad(149);
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['osobneCislo'];
            $policka = "<input type=\"text\" name=\"osobneCislo\" />";
        } elseif ($uprava == 103) {
            $nazov = preklad(150);
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['costCenter'];
            $policka = "<input type=\"text\" name=\"costCenter\" />";
        } elseif ($uprava == 104) {
            $nazov = preklad(151);
            $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['fond'];
            $policka = "<input type=\"text\" name=\"fond\" />";
        } elseif ($uprava == 22) {
            $nazov = preklad(47);
            $nac_s = "SELECT * FROM z_datum_ukonc_posled_zam WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $dat_ukonc = date_conv_to_view($nac['datum_ukoncenia']);
            if ($dat_ukonc > "00.00.0000")
                $povod_hodn = $dat_ukonc;
            else
                $povod_hodn = "";
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<input type=\"text\" name=\"datum_ukoncenia\" id=\"datum_ukoncenia\" readonly /> <a href=\"javascript:NewCssCal('datum_ukoncenia','ddmmyyyy')\"><img src=\"images/cal.gif\" width=\"16\" height=\"16\" alt=\"Pick a date\" border=\"0\"></a>";
            $over_toto[] = "datum_ukoncenia,Dátum ukončenia posledného zamestnania";
        }
        elseif ($uprava == 23) {
            $nazov = preklad(48);
            $nac_s = "SELECT * FROM z_ostatne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['ostatne'];
            if ($nac['active'] == 0)
                $povod_hodn = "";
            $policka = "<textarea name=\"ostatne\"></textarea>";
            $over_toto[] = "ostatne,Ostatné údaje";
        }
        elseif ($uprava == 24) {
            $nazov = preklad(49);
            $nac_s = "SELECT stav.stav FROM z,stav WHERE z.id = '" . $zid . "' AND stav.id = z.stavid ";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['stav'];
            $policka = "<select name=\"stav\">";
            $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
            $stavy_q = MySQL_Query($stavy_s);
            while ($stavy = MySQL_Fetch_Array($stavy_q)) {
                $policka .= "<option value=\"" . $stavy['id'] . "\">" . preklad($stavy['jazyk_id']) . "</option>";
            }
            $policka .= "</select>\n";
            $over_toto[] = "stav,Stav";
        } elseif ($uprava == 25) {
            global $vypis;
            $nazov = preklad(126);
            $nac_s = "SELECT mail,ip FROM z WHERE id = '" . $zid . "' ";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $povod_hodn = $nac['mail'] . ((!Empty($nac['ip'])) ? ", " . $nac['ip'] : "");
            $policka = "<table>";
            $policka .= "<tr><td><b>" . preklad(127) . "</b></td><td><input type=\"text\" name=\"z_mail\" value=\"" . $nac['mail'] . "\" /></td></tr>\n";
            $policka .= "<tr><td><b>" . preklad(128) . "</b></td><td><input type=\"password\" name=\"z_heslo\" /></td></tr>\n";
            $policka .= "<tr><td><b>" . preklad(129) . "</b></td><td><input type=\"text\" name=\"z_ip\" value=\"" . $nac['ip'] . "\" /></td></tr>\n";
            $policka .= "<tr><td colspan=2><font color=\"red\">" . $vypis . "</font></td></tr>\n";
            $policka .= "</table>";
        } elseif ($uprava == 88) {
            if (!$falkModeAdmin) {
                $policka = "Na túto úpravu nemáte oprávnenie.";
            } else {
                $nac_s = "SELECT manager,veduci_oddelenia,patri_k FROM z WHERE id = '" . $zid . "' ";
                $nac_q = MySQL_Query($nac_s);
                $nac = MySQL_Fetch_Array($nac_q);
                $policka = "<table>";
                $check1 = '';
                if ($nac['manager'] == 1) {
                    $policka .= "<tr><td><b>" . preklad(157) . ":</b></td><td>";
                    $policka .= '<select id="manazer" onchange="vyberVeduceho()" name="manazer">';
                    $policka .= '<option value="0">Zamestnanec</option>';
                    $policka .= '<option value="1" selected>Manažér</option>';
                    $policka .= '<option value="2">Dohodár</option>';
                    $policka .= '</select>';
                    $policka .= "</td></tr>\n";
                    $policka .= "<tr id=\"vyberVeduceho\"><td><b>" . preklad(141) . ":</b></td><td>";
                    $policka .= '<select name="veduci" size="1">';
                    $pr_s = "SELECT * FROM oddelenie ORDER BY nazov ASC";
                    $pr_q = MySQL_Query($pr_s);
                    while ($pr = MySQL_Fetch_Array($pr_q)) {
                        if ($pr['id'] == $nac['patri_k'])
                            $policka .= "<option selected value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                        else
                            $policka .= "<option value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                    }
                    $policka .= '</select>';
                    $policka .= "</td></tr>\n";
                    $policka .= "<tr id=\"manazer_oddelenia\"><td><b>" . preklad(139) . "</b></td><td>";
                    $policka .= "<select name=\"manazer_oddelenia\" size=\"1\" >";
                    $policka .= "<option value=\"0\">" . preklad(156) . "</option>";
                    $pr_s = "SELECT * FROM oddelenie ORDER BY nazov ASC";
                    $pr_q = MySQL_Query($pr_s);
                    while ($pr = MySQL_Fetch_Array($pr_q)) {
                        if ($pr['id'] == $nac['veduci_oddelenia'])
                            $policka .= "<option selected value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                        else
                            $policka .= "<option value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                    }
                    $policka .= "</select></td></tr>\n";
                } else {
                    $policka .= "<tr><td><b>" . preklad(157) . ":</b></td><td>";
                    $policka .= '<select id="manazer" onchange="vyberVeduceho()" name="manazer">';
                    $doh = '';
                    $zamestn = '';
                    if ($nac['manager'] == 0) {
                        $zamestn = 'selected';
                        $doh = '';
                    } else {
                        $zamestn = '';
                        $doh = 'selected';
                    }
                    $policka .= '<option value="0" ' . $zamestn . '>Zamestnanec</option>';
                    $policka .= '<option value="1">Manažér</option>';
                    $policka .= '<option value="2" ' . $doh . '>Dohodár</option>';
                    $policka .= '</select>';
                    $policka .= "</td></tr>\n";
                    $policka .= "<tr id=\"vyberVeduceho\"><td><b>" . preklad(141) . ":</b></td><td>";
                    $policka .= '<select name="veduci" size="1">';
                    $pr_s = "SELECT * FROM oddelenie ORDER BY nazov ASC";
                    $pr_q = MySQL_Query($pr_s);
                    while ($pr = MySQL_Fetch_Array($pr_q)) {
                        if ($pr['id'] == $nac['patri_k'])
                            $policka .= "<option selected value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                        else
                            $policka .= "<option value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                    }
                    $policka .= '</select>';
                    $policka .= "</td></tr>\n";
                    $policka .= "<tr style=\"display: none\" id=\"manazer_oddelenia\"><td><b>" . preklad(139) . "</b></td><td>";
                    $policka .= "<select name=\"manazer_oddelenia\" size=\"1\" >";
                    $policka .= "<option value=\"0\">" . preklad(156) . "</option>";
                    $pr_s = "SELECT * FROM oddelenie ORDER BY nazov ASC";
                    $pr_q = MySQL_Query($pr_s);
                    while ($pr = MySQL_Fetch_Array($pr_q)) {
                        if ($pr['id'] == $nac['veduci_oddelenia'])
                            $policka .= "<option selected value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                        else
                            $policka .= "<option value=\"" . $pr['id'] . "\">" . $pr['nazov'] . "</option>";
                    }
                    $policka .= "</select></td></tr>\n";
                }
                $policka .= "<tr><td colspan=2><font color=\"red\">" . $vypis . "</font></td></tr>\n";
                $policka .= "</table>";
                $upravaManagera = true;
            }
        }
        if ($upravaManagera) {
            echo "<form action=\"home.php?akc=3&akc2=4&uprava=" . $uprava . "&zid=" . $zid . "\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\" onsubmit=\"return check();\"><table>";
            echo "<tr><td><b>" . $nazov . "</b></td><td>" . $policka . "</td></tr>";
            echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
            echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"zid\" value=\"" . $zid . "\" /><input name=\"upravitManazera\" type=\"submit\" value=\"" . preklad(60) . "\" /></td></tr>";
            echo "</table></form>";
        } else {
            check_js($over_toto);

            $nevyplnene = "<font class=\"gray\">" . preklad(72) . "</font>";
            echo "<form action=\"home.php?akc=3&akc2=4&uprava=" . $uprava . "&zid=" . $zid . "\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\" onsubmit=\"return check();\"><table>";
            echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(71) . "</td></tr>";
            echo "<tr><td><b>" . $nazov . "</b></td><td>" . ((trim($povod_hodn) != '') ? $povod_hodn : $nevyplnene) . "</td></tr>";
            echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
            echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">" . preklad(70) . "</td></tr>";
            echo "<tr><td><b>" . $nazov . "</b></td><td>" . $policka . "</td></tr>";
            echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
            echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"uloz_zam_spol_3_up\" value=\"1\" /><input type=\"hidden\" name=\"zmena_coho\" value=\"" . $nazov . "\" /><input type=\"submit\" value=\"" . preklad(60) . "\" /></td></tr>";
            echo "</table></form>";
        }
    } else {
        echo "takýto zamestnanec neexistuje!";
    }
}

function profil_zamestnanec_spol3_uprava_uloz() {
    $zid = $_GET['zid'];
    $povol = pristup_zid("$zid");
    if ($povol == 1) {
        $prec = 0;
        $akt_dat = Date("Y-m-d");
        $uprava = IntVal($_GET['uprava']);
        if ($uprava == 1) {
            $meno_ok = Trim(HtmlSpecialChars($_POST['meno'], ENT_QUOTES));
            if (!Empty($meno_ok)) {
                $zmen_i = "INSERT INTO z_meno (id, meno, datum_pridania, zid) VALUES (NULL, '" . $meno_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $zmen2_u = "UPDATE z SET meno = '" . $meno_ok . "' WHERE id = '" . $zid . "' ";
                $zmen2_q = MySQL_Query($zmen2_u);
                $prec = 1;
            }
        } elseif ($uprava == 2) {
            $priezvisko_ok = Trim(HtmlSpecialChars($_POST['priezvisko'], ENT_QUOTES));
            if (!Empty($priezvisko_ok)) {
                $zmen_i = "INSERT INTO z_priezvisko (id, priezvisko, datum_pridania, zid) VALUES (NULL, '" . $priezvisko_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $zmen2_u = "UPDATE z SET priezvisko = '" . $priezvisko_ok . "' WHERE id = '" . $zid . "' ";
                $zmen2_q = MySQL_Query($zmen2_u);
                $prec = 1;
            }
        } elseif ($uprava == 3) {
            $titul_ok = Trim(HtmlSpecialChars($_POST['titul'], ENT_QUOTES));
            if (!Empty($titul_ok)) {
                $zmen0_u = "UPDATE z_titul SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_titul (id, titul, datum_pridania, zid, active) VALUES (NULL, '" . $titul_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 4) {
            $priezvisko_rodne_ok = Trim(HtmlSpecialChars($_POST['priezvisko_rodne'], ENT_QUOTES));
            if (!Empty($priezvisko_rodne_ok)) {
                $zmen_i = "INSERT INTO z_priezvisko_rodne (id, priezvisko_rodne, datum_pridania, zid) VALUES (NULL, '" . $priezvisko_rodne_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 5) {
            $rodne_cislo1_ok = Trim(HtmlSpecialChars($_POST['rodne_cislo1'], ENT_QUOTES));
            $rodne_cislo2_ok = Trim(HtmlSpecialChars($_POST['rodne_cislo2'], ENT_QUOTES));
            if (!Empty($rodne_cislo1_ok) && !Empty($rodne_cislo1_ok)) {
                $zmen_i = "INSERT INTO z_rodne_cislo (id, cislo1, cislo2, datum_pridania, zid) VALUES (NULL, '" . $rodne_cislo1_ok . "', '" . $rodne_cislo2_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 6) {
            $datum_narodenia_ok = Trim(HtmlSpecialChars($_POST['datum_narodenia'], ENT_QUOTES));
            $datum_narodenia_db = date_conv_to_db("$datum_narodenia_ok");
            if (!Empty($datum_narodenia_ok)) {
                $zmen_i = "INSERT INTO z_datum_narodenia (id, datum_narodenia, datum_pridania, zid) VALUES (NULL, '" . $datum_narodenia_db . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 7) {
            $miesto_narodenia_ok = Trim(HtmlSpecialChars($_POST['miesto_narodenia'], ENT_QUOTES));
            if (!Empty($miesto_narodenia_ok)) {
                $zmen_i = "INSERT INTO z_miesto_narodenia (id, miesto, datum_pridania, zid) VALUES (NULL, '" . $miesto_narodenia_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 8) {
            $tel_cislo_ok = Trim(HtmlSpecialChars($_POST['tel_cislo'], ENT_QUOTES));
            if (!Empty($tel_cislo_ok)) {
                $zmen0_u = "UPDATE z_tel_cislo SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_tel_cislo (id, tel, datum_pridania, zid, active) VALUES (NULL, '" . $tel_cislo_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 9) {
            $narodnost_ok = Trim(HtmlSpecialChars($_POST['narodnost'], ENT_QUOTES));
            if (!Empty($narodnost_ok)) {
                $zmen_i = "INSERT INTO z_narodnost (id, narodnost, datum_pridania, zid) VALUES (NULL, '" . $narodnost_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 10) {
            $statna_prislusnost_ok = Trim(HtmlSpecialChars($_POST['statna_prislusnost'], ENT_QUOTES));
            if (!Empty($statna_prislusnost_ok)) {
                $zmen_i = "INSERT INTO z_statna_prislusnost (id, prislusnost, datum_pridania, zid) VALUES (NULL, '" . $statna_prislusnost_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 11) {
            $obciansky_preukaz_ok = Trim(HtmlSpecialChars($_POST['obciansky_preukaz'], ENT_QUOTES));
            if (!Empty($obciansky_preukaz_ok)) {
                $zmen0_u = "UPDATE z_obciansky_preukaz SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_obciansky_preukaz (id, obciansky, datum_pridania, zid, active) VALUES (NULL, '" . $obciansky_preukaz_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 12) {
            $vodicsky_preukaz_ok = Trim(HtmlSpecialChars($_POST['vodicsky_preukaz'], ENT_QUOTES));
            if (!Empty($vodicsky_preukaz_ok)) {
                $zmen0_u = "UPDATE z_vodicsky_preukaz SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_vodicsky_preukaz (id, vodicsky, datum_pridania, zid, active) VALUES (NULL, '" . $vodicsky_preukaz_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 13) {
            $rodinny_stav_ok = Trim(HtmlSpecialChars($_POST['rodinny_stav'], ENT_QUOTES));
            if (!Empty($rodinny_stav_ok)) {
                $zmen_i = "INSERT INTO z_rodinny_stav (id, stav, datum_pridania, zid) VALUES (NULL, '" . $rodinny_stav_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 14) {
            $zdravotny_stav_ok = Trim(HtmlSpecialChars($_POST['zdravotny_stav'], ENT_QUOTES));
            if (!Empty($zdravotny_stav_ok)) {
                $zmen0_u = "UPDATE z_zdravotny_stav SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_zdravotny_stav (id, stav, datum_pridania, zid, active) VALUES (NULL, '" . $zdravotny_stav_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 15) {
            $poistovna_ok = IntVal($_POST['poistovna']);
            if (!Empty($poistovna_ok)) {
                $zmen_i = "INSERT INTO z_zdravotna_poistovna (id, pid, datum_pridania, zid) VALUES (NULL, '" . $poistovna_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 16) {
            $t_ulica_ok = Trim(HtmlSpecialChars($_POST['t_ulica'], ENT_QUOTES));
            $t_mesto_ok = Trim(HtmlSpecialChars($_POST['t_mesto'], ENT_QUOTES));
            $t_psc_ok = Trim(HtmlSpecialChars($_POST['t_psc'], ENT_QUOTES));
            $t_tel_ok = Trim(HtmlSpecialChars($_POST['t_tel'], ENT_QUOTES));
            if (!Empty($t_ulica_ok) && !Empty($t_mesto_ok) && !Empty($t_psc_ok)) {
                $zmen_i = "INSERT INTO z_bydlisko_trvale (id, ulica, psc, mesto, tel, datum_pridania, zid) VALUES (NULL, '" . $t_ulica_ok . "', '" . $t_psc_ok . "', '" . $t_mesto_ok . "', '" . $t_tel_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 17) {
            $p_ulica_ok = Trim(HtmlSpecialChars($_POST['p_ulica'], ENT_QUOTES));
            $p_mesto_ok = Trim(HtmlSpecialChars($_POST['p_mesto'], ENT_QUOTES));
            $p_psc_ok = Trim(HtmlSpecialChars($_POST['p_psc'], ENT_QUOTES));
            $p_tel_ok = Trim(HtmlSpecialChars($_POST['p_tel'], ENT_QUOTES));
            if (!Empty($p_ulica_ok) && !Empty($p_mesto_ok) && !Empty($p_psc_ok)) {
                $zmen0_u = "UPDATE z_bydlisko_prechodne SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_bydlisko_prechodne (id, ulica, psc, mesto, tel, datum_pridania, zid, active) VALUES (NULL, '" . $p_ulica_ok . "', '" . $p_psc_ok . "', '" . $p_mesto_ok . "', '" . $p_tel_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 18) {
            $pred_ok = Trim(HtmlSpecialChars($_POST['pred'], ENT_QUOTES));
            $ucet_ok = Trim(HtmlSpecialChars($_POST['ucet'], ENT_QUOTES));
            $banka_ok = Trim(HtmlSpecialChars($_POST['banka'], ENT_QUOTES));
            if (!Empty($ucet_ok) && !Empty($banka_ok)) {
                $zmen_i = "INSERT INTO z_cislo_uctu (id, cislo0, cislo1, cislo2, datum_pridania, zid) VALUES (NULL, '" . $pred_ok . "', '" . $ucet_ok . "', '" . $banka_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 19) {
            $datum_nastupu_ok = Trim(HtmlSpecialChars($_POST['datum_nastupu']));
            $datum_nastupu_db = date_conv_to_db("$datum_nastupu_ok");
            if (!Empty($datum_nastupu_ok)) {
                $zmen_u = "UPDATE z SET datum_prichodu = '" . $datum_nastupu_db . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 20) {
            $datum_vypovede_ok = Trim(HtmlSpecialChars($_POST['datum_vypovede']));
            $datum_vypovede_db = date_conv_to_db("$datum_vypovede_ok");
            if (!Empty($datum_vypovede_ok)) {
                $zmen_u = "UPDATE z SET datum_odchodu = '" . $datum_vypovede_db . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 21) {
            $druh_pomeru_ok = Trim(HtmlSpecialChars($_POST['druh_pomeru']));
            if (!Empty($druh_pomeru_ok)) {
                $zmen_i = "INSERT INTO z_druh_pomeru (id, druh, datum_pridania, zid) VALUES (NULL, '" . $druh_pomeru_ok . "', '" . $akt_dat . "', '" . $zid . "')";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 101) {
            $datum_nastupu_ok = Trim(HtmlSpecialChars($_POST['pozicia']));
            if (!Empty($datum_nastupu_ok)) {
                $zmen_u = "UPDATE z SET pozicia = '" . $datum_nastupu_ok . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 102) {
            $datum_nastupu_ok = Trim(HtmlSpecialChars($_POST['osobneCislo']));
            if (!Empty($datum_nastupu_ok)) {
                $zmen_u = "UPDATE z SET osobneCislo = '" . $datum_nastupu_ok . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 103) {
            $datum_nastupu_ok = Trim(HtmlSpecialChars($_POST['costCenter']));
            if (!Empty($datum_nastupu_ok)) {
                $zmen_u = "UPDATE z SET costCenter = '" . $datum_nastupu_ok . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 104) {
            $datum_nastupu_ok = Trim(HtmlSpecialChars($_POST['fond']));
            if (trim($datum_nastupu_ok) != '') {
                $zmen_u = "UPDATE z SET fond = '" . $datum_nastupu_ok . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 22) {
            $datum_ukoncenia_ok = Trim(HtmlSpecialChars($_POST['datum_ukoncenia']));
            $datum_ukoncenia_db = date_conv_to_db("$datum_ukoncenia_ok");
            if (!Empty($datum_ukoncenia_ok)) {
                $zmen0_u = "UPDATE z_datum_ukonc_posled_zam SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_datum_ukonc_posled_zam (id, datum_ukoncenia, datum_pridania, zid, active) VALUES (NULL, '" . $datum_ukoncenia_db . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 23) {
            $ostatne_ok = Trim(HtmlSpecialChars($_POST['ostatne']));
            $ostatne_ok = zalamovanie_do_db("$ostatne_ok");
            if (!Empty($ostatne_ok)) {
                $zmen0_u = "UPDATE z_ostatne SET active = 0 WHERE zid = '" . $zid . "' ";
                $zmen0_q = MySQL_Query($zmen0_u);
                $zmen_i = "INSERT INTO z_ostatne (id, ostatne, datum_pridania, zid, active) VALUES (NULL, '" . $ostatne_ok . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $zmen_q = MySQL_Query($zmen_i);
                $prec = 1;
            }
        } elseif ($uprava == 24) {
            $stav_ok = IntVal($_POST['stav']);
            if (!Empty($stav_ok)) {
                $zmen_u = "UPDATE z SET stavid = '" . $stav_ok . "' WHERE id = '" . $zid . "' ";
                $zmen_q = MySQL_Query($zmen_u);
                $prec = 1;
            }
        } elseif ($uprava == 25) {
            $mail_ok = $_POST['z_mail'];
            $ip_ok = $_POST['z_ip'];
            $heslo_ok = MD5($_POST['z_heslo']);
            $over_mail_s = "SELECT id FROM user WHERE mail = '" . $mail_ok . "' AND mail <> '' ";
            $over_mail_q = MySQL_Query($over_mail_s);
            $over_mail_n = MySQL_Num_Rows($over_mail_q);
            if ($over_mail_n == 0) {
                $over_2_s = "SELECT id FROM z WHERE mail = '" . $mail_ok . "' AND mail <> '' AND id <> '" . $zid . "' ";
                $over_2_q = MySQL_Query($over_2_s);
                $over_2_n = MySQL_Num_Rows($over_2_q);
                if ($over_2_n == 0) {
                    if (Eregi("^[_a-zA-Z0-9]+([-\.][_a-zA-Z0-9]+)*@[_a-zA-Z0-9]+([-\.][_a-zA-Z0-9]+)*\.[_a-zA-Z0-9]{2,4}$", $mail_ok) && !Empty($heslo_ok)) {
                        $zmen_u = "UPDATE z SET mail = '" . $mail_ok . "', ip = '" . $ip_ok . "', heslo = '" . $heslo_ok . "' WHERE id = '" . $zid . "' ";
                        $zmen_q = MySQL_Query($zmen_u);
                        $prec = 1;
                    } elseif (Empty($mail_ok) && Empty($_POST['z_heslo'])) {
                        $zmen_u = "UPDATE z SET mail = '', ip = '', heslo = '' WHERE id = '" . $zid . "' ";
                        $zmen_q = MySQL_Query($zmen_u);
                        $prec = 1;
                    } else {
                        global $vypis;
                        $vypis = "Zadaný e-mail nie je v správnej forme.";
                    }
                } else {
                    global $vypis;
                    $vypis = "Tento e-mail nie je možné použiť.";
                }
            } else {
                global $vypis;
                $vypis = "Tento e-mail nie je možné použiť.";
            }
        }

        $zmena_coho_ok = Trim(HtmlSpecialChars($_POST['zmena_coho'], ENT_QUOTES));
        if (!Empty($zmena_coho_ok) && $prec == 1) {
            $spolid_s = "SELECT spolid,meno,priezvisko FROM z WHERE id = '" . $zid . "' ";
            $spolid_q = MySQL_Query($spolid_s);
            $spolid = MySQL_Fetch_Array($spolid_q);

            $starost_s = "SELECT spolocnost.nazov,spolocnost.uid,user.mail FROM spolocnost,user WHERE spolocnost.id = '" . $spolid['spolid'] . "' AND user.id = spolocnost.uid ";
            $starost_q = MySQL_Query($starost_s);
            $starost = MySQL_Fetch_Array($starost_q);
            $komu = $starost['mail'];
            $predmet = "mzdy.bmbleitner.sk";
            $text = "Spoločnosť " . $starost['nazov'] . " zmenila údaj <b>" . $zmena_coho_ok . "</b> pri zamestnancovi: <b>" . $spolid['priezvisko'] . " " . $spolid['meno'] . "</b>.";

            poslat_email($komu, $predmet, $text);
        }
        if ($prec == 1) {
            Header("Location: home.php?akc=3&akc2=4&zid=" . $zid);
            exit();
        }
    } else {
        Header("Location: index.php");
        exit();
    }
}

function profil_zamestnanec_spol3_neaktual($zid, $neaktual) {
    $povol = pristup_zid("$zid");
    if ($povol == 1) {
        $zoznam = Array(3, 8, 11, 12, 14, 17, 20, 22, 23);
        if (In_Array($neaktual, $zoznam)) {
            $tab[3] = "z_titul";
            $tab[8] = "z_tel_cislo";
            $tab[11] = "z_obciansky_preukaz";
            $tab[12] = "z_vodicsky_preukaz";
            $tab[14] = "z_zdravotny_stav";
            $tab[17] = "z_bydlisko_prechodne";
            $tab[20] = "datum_odchodu";
            $tab[22] = "z_datum_ukonc_posled_zam";
            $tab[23] = "z_ostatne";
            if ($neaktual != 20) {
                $zmen_u = "UPDATE " . $tab[$neaktual] . " SET active = 0 WHERE zid = '" . $zid . "' ";
            } else {
                $zmen_u = "UPDATE z SET " . $tab[$neaktual] . " = '0000.00.00' WHERE id = '" . $zid . "' ";
            }
            $zmen_q = MySQL_Query($zmen_u);
            Header("Location: home.php?akc=3&akc2=4&zid=" . $zid);
            exit();
        } else {
            Header("Location: index.php");
            exit();
        }
    } else {
        Header("Location: index.php");
        exit();
    }
}

function zmen_sviat($zobraz) {
    $_SESSION['rok_sviatkov'] = $zobraz;
    Header("Location: ?akc=5");
    exit();
}

function sviatky_zobraz() {
    echo "<h2>Sviatky</h2>\n";
    if (!Empty($_SESSION['rok_sviatkov']))
        $rok = $_SESSION['rok_sviatkov'];
    else
        $rok = Date("Y");
    echo "zobraziť rok: <select onChange=\"jm(this)\" size=\"1\">";
    $prvy_rok = 2009;
    $aktual_rok = Date("Y");
    $posled_rok = $aktual_rok + 1;
    for ($i = $prvy_rok; $i <= $posled_rok; $i++) {
        echo "<option value=\"" . $i . "\"" . (($i == $rok) ? " selected" : "") . ">" . $i . "</option>";
    }
    echo "</select>\n";
    echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?sviatok=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
    echo "<br /><br />";

    $over_toto[] = "den,Deň";
    $over_toto[] = "mesiac,Mesiac";

    check_js($over_toto);

    echo "<form action=\"\" method=\"post\" name=\"formular\" onsubmit=\"return check();\">\n";
    echo "<div style=\"padding:5px;margin:5px;background:#eee;\">";
    echo "pridať sviatok: <select name=\"den\"><option value=\"\"> - </option>";
    for ($i = 1; $i <= 31; $i++) {
        echo "<option value=\"" . $i . "\">" . $i . "</option>";
    }
    echo "</select>\n";
    echo "<select name=\"mesiac\"><option value=\"\"> - - - </option>";
    $mes_s = "SELECT * FROM mesiac ORDER BY id ASC";
    $mes_q = MySQL_Query($mes_s);
    while ($mes = MySQL_Fetch_Array($mes_q)) {
        echo "<option value=\"" . $mes['id'] . "\">" . $mes['nazov'] . "</option>";
    }
    echo "</select>\n";
    echo "<input type=\"hidden\" name=\"sviatky_pridat\" value=\"1\"><input type=\"submit\" value=\"pridaj\">";
    echo "</div>";
    echo "</form>\n";
    echo "<br />\n";
    echo "<b>Sviatky roku " . $rok . ":</b>\n";
    echo "<br /><br />\n";
    $sviatky_s = "SELECT sviatok.id,sviatok.den,mesiac.nazov FROM sviatok,mesiac WHERE sviatok.rok = '" . $rok . "' AND mesiac.id = sviatok.mesiac ORDER BY sviatok.mesiac,sviatok.den ASC";
    $sviatky_q = MySQL_Query($sviatky_s);
    while ($sviatky = MySQL_Fetch_Array($sviatky_q)) {
        echo $sviatky['den'] . ". " . $sviatky['nazov'] . " <a href=\"?sviatok_del=1&s=" . $sviatky['id'] . "\">x</a><br />\n";
    }
}

function sviatok_pridaj() {
    if (!Empty($_POST['den']) && !Empty($_POST['mesiac'])) {
        $den_ok = IntVal($_POST['den']);
        $mesiac_ok = IntVal($_POST['mesiac']);
        if ($den_ok > 0 && $mesiac_ok > 0) {
            if (!Empty($_SESSION['rok_sviatkov']))
                $rok_ok = $_SESSION['rok_sviatkov'];
            else
                $rok_ok = Date("Y");

            $pocet_dni = cal_days_in_month(CAL_GREGORIAN, $mesiac_ok, $rok_ok);

            if ($den_ok <= $pocet_dni) {
                $dat = $den_ok . "." . $mesiac_ok . "." . $rok_ok;
                $dat_ok = date_conv_to_db($dat);
                $sv_d = "DELETE FROM sviatok WHERE den = '" . $den_ok . "' AND mesiac = '" . $mesiac_ok . "' AND rok = '" . $rok_ok . "' AND datum = '" . $dat_ok . "'";
                $sv_q = MySQL_Query($sv_d);
                $sviatok_i = "INSERT INTO sviatok (id, den, mesiac, rok, datum) VALUES (NULL, '" . $den_ok . "', '" . $mesiac_ok . "', '" . $rok_ok . "', '" . $dat_ok . "') ";
                $sviatok_q = MySQL_Query($sviatok_i);
            }
        }
    }
    Header("Location: ?akc=5");
    exit();
}

function sviatok_vymazat($sviatok) {
    $zmaz_d = "DELETE FROM sviatok WHERE id = '" . $sviatok . "' ";
    $zmaz_q = MySQL_Query($zmaz_d);

    Header("Location: ?akc=5");
    exit();
}

function zoznam_docs_vzor($ci_admin) {
    $docs_s = "SELECT * FROM vzor_docs WHERE active = 1 ORDER BY nazov ASC";
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    if ($docs_n > 0) {
        $i = 1;
        if ($ci_admin == 1)
            echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nfunction odstranit(nazov)\n{\nreturn confirm(\"Naozaj chcete odstrániť vzorový dokument \" + nazov + \"?\");\n}\n//-->\n</script>\n";
        $ret = "<table>";
        $ret .= "<tr><td>#</td><td>" . preklad(66) . "</td>" . (($ci_admin == 1) ? "<td>" . preklad(67) . "</td><td>&nbsp;</td>" : "") . "</tr>";
        while ($docs = MySQL_Fetch_Array($docs_q)) {
            $ret .= "<tr><td>" . $i . "</td><td><a href=\"get_file_vzor.php?did=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td>" . (($ci_admin == 1) ? "<td>" . date_conv_to_view($docs['datum_pridania']) . "</td><td><a href=\"?del_doc_vzor=1&did=" . $docs['id'] . "\" onclick=\"return odstranit('" . $docs['nazov'] . "');\">vymazať</a></td>" : "" ) . "</tr>";
            $i++;
        }
        $ret .= "</table>";
    }
    return $ret;
}

function vzor_dokument_admin() {
    echo "<h2>Vzorové dokumenty</h2>\n";
    echo "<form action=\"\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\">\n";
    echo form_viac_suborov(5);
    echo "<input type=\"hidden\" name=\"uloz_vzor_doc\" value=\"1\" /><input type=\"submit\" value=\"Uložiť\" />";
    echo "</form>";
    echo "<br /><br />";
    echo zoznam_docs_vzor(1);
}

function vzor_dokument_admin_uloz() {
    if (!Empty($_FILES['subor']['name'])) {
        $i = 1;
        while (list($key, $value) = each($_FILES['subor']['name'])) {
            if (!Empty($value)) {
                $filename = Trim(HtmlSpecialChars($value));
                $filename = Str_Replace(" ", "_", $filename);
                $ftp = "document_vzor_" . MD5(MicroTime()) . "_" . $i;
                $document = $_FILES['subor']['tmp_name'][$key];
                $type = ($_FILES['subor']['type'][$key]);
                @mkdir($document, 0777);
                @chmod($document, 0777);
                if (Move_Uploaded_File($document, DOCS_ADDRESS . $ftp)) {
                    $akt_dat = Date("Y-m-d");
                    $uloz_i = "INSERT INTO vzor_docs (id, nazov, ftp, type, datum_pridania, len_admin, spracovat, active) VALUES (NULL, '" . $filename . "', '" . $ftp . "', '" . $type . "', '" . $akt_dat . "', 0, 0, 1)";
                    $uloz_q = MySQL_Query($uloz_i);
                }
                $i++;
            }
        }
    }
    Header("Location: ?akc=6");
    exit();
}

function vzor_dokument_vymazat($doc) {
    $zmaz_u = "UPDATE vzor_docs SET active = 0 WHERE id = '" . $doc . "' ";
    $zmaz_q = MySQL_Query($zmaz_u);

    Header("Location: ?akc=6");
    exit();
}

function zoznam_docs_firma() {
    $ord = Array("nazov", "datum_pridania");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }

    global $user_id;
    $len_s = "SELECT spolid,admin FROM user WHERE id = '" . $user_id . "' ";
    $len_q = MySQL_Query($len_s);
    $len = MySQL_Fetch_Array($len_q);
    $spolid = $len['spolid'];

    $docs_s = "SELECT * FROM spol_docs WHERE spolid = '" . $spolid . "' AND len_admin <= '" . $len['admin'] . "' AND active = 1 ORDER BY " . $order_ok . " " . $asc_ok;
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    $i = 1;
    $ret = "<table>";
    $ret .= "<tr><td>#</td><td><a href=\"?akc=7&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(66) . "</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=7&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(67) . "</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>&nbsp;</td></tr>";
    while ($docs = MySQL_Fetch_Array($docs_q)) {
        $ret .= "<tr><td>" . $i . "</td><td><a href=\"get_file_spol.php?did=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td><td>";
        if ($len['admin'] == 1)
            $ret .= "<a href=\"?del_sdoc=1&id=" . $docs['id'] . "\">vymazať</a>";
        else
            $ret .= "&nbsp;";
        $ret .= "</td></tr>";
        $i++;
    }
    $ret .= "</table>";
    return $ret;
}

function spol_docs_vymazat($doc) {
    global $user_id;
    $len_s = "SELECT spolid,admin FROM user WHERE id = '" . $user_id . "' ";
    $len_q = MySQL_Query($len_s);
    $len = MySQL_Fetch_Array($len_q);
    $spolid = $len['spolid'];

    if ($len['admin'] == 1) {
        $zmaz_u = "UPDATE spol_docs SET active = 0 WHERE id = '" . $doc . "' AND spolid = '" . $spolid . "' ";
        $zmaz_q = MySQL_Query($zmaz_u);
    }

    Header("Location: ?akc=7");
    exit();
}

function dokument_user() {
    echo "<h2>" . preklad(74) . "</h2>\n";
    echo "<b>" . preklad(75) . "</b>\n";
    echo zoznam_docs_vzor(0);
    echo "<br /><br />";
    global $user_id;
    $nac_s = "SELECT meno,priezvisko,spolid,admin FROM user WHERE id = '" . $user_id . "' ";
    $nac_q = MySQL_Query($nac_s);
    $nac = MySQL_Fetch_Array($nac_q);
    $ret = "<b>" . $nac['meno'] . " " . $nac['priezvisko'] . "</b>";
    if ($nac['spolid'] > 0) {
        $nac2_s = "SELECT nazov FROM spolocnost WHERE id = '" . $nac['spolid'] . "' ";
        $nac2_q = MySQL_Query($nac2_s);
        $nac2 = MySQL_Fetch_Array($nac2_q);
        $nazov_firmy = $nac2['nazov'];
    }
    echo "<b>" . preklad(76) . " " . $nazov_firmy . ":</b>\n";
    echo "<form action=\"\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\">\n";
    echo form_viac_suborov(5);
    echo "<input type=\"checkbox\" name=\"dolezite\" value=\"1\"> " . preklad(77) . "<br /><input type=\"hidden\" name=\"uloz_doc\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" />";
    echo "</form>";
    echo "<br / >";
    echo zoznam_docs_firma();
}

function dokument_user_uloz() {
    if (!Empty($_FILES['subor']['name'])) {
        $nazvy = "";
        $i = 1;
        while (list($key, $value) = each($_FILES['subor']['name'])) {
            if (!Empty($value)) {
                global $user_id;
                $nac_s = "SELECT meno,priezvisko,spolid,admin FROM user WHERE id = '" . $user_id . "' ";
                $nac_q = MySQL_Query($nac_s);
                $nac = MySQL_Fetch_Array($nac_q);
                $spolid = $nac['spolid'];

                $filename = Trim(HtmlSpecialChars($value));
                $filename = Str_Replace(" ", "_", $filename);
                $ftp = "document_spol_" . $spolid . "_" . MD5(MicroTime()) . "_" . $i;
                $document = $_FILES['subor']['tmp_name'][$key];
                $type = ($_FILES['subor']['type'][$key]);
                @mkdir($document, 0777);
                @chmod($document, 0777);
                if (Move_Uploaded_File($document, DOCS_ADDRESS . $ftp)) {
                    $nazvy .= $filename . ", ";
                    global $user_id;
                    $len_s = "SELECT admin FROM user WHERE id = '" . $user_id . "' ";
                    $len_q = MySQL_Query($len_s);
                    $len = MySQL_Fetch_Array($len_q);
                    $akt_dat = Date("Y-m-d");
                    $uloz_i = "INSERT INTO spol_docs (id, nazov, ftp, type, datum_pridania, datum_spracovania, spolid, len_admin, spracovat, active) VALUES (NULL, '" . $filename . "', '" . $ftp . "', '" . $type . "', '" . $akt_dat . "', '0000-00-00', '" . $spolid . "', '" . $len['admin'] . "', 1, 1)";
                    $uloz_q = MySQL_Query($uloz_i);
                }
                $i++;
            }
        }
        $nazvy = substr($nazvy, 0, -2);
        if ($i > 1) {
            if ($_POST['dolezite'] == 1) {
                $starost_s = "SELECT spolocnost.nazov,spolocnost.uid,user.mail FROM spolocnost,user WHERE spolocnost.id = '" . $spolid . "' AND user.id = spolocnost.uid ";
                $starost_q = MySQL_Query($starost_s);
                $starost = MySQL_Fetch_Array($starost_q);
                $komu = $starost['mail'];
                $predmet = "mzdy.bmbleitner.sk";
                $text = "Spoločnosť " . $starost['nazov'] . " pridala nové dokumenty: " . $nazvy;

                poslat_email($komu, $predmet, $text);
            }
        }
    }
    Header("Location: ?akc=7");
    exit();
}

function dochadzka_sel($den_typ, $zid, $den, $mes, $rok, $prac_vikend, $s, $prac_sviatok) {
    $dat = $den . "." . $mes . "." . $rok;
    $dat_db = date_conv_to_db($dat);
    if ($den_typ < 6) {
        $prac_s = "SELECT * FROM praca WHERE tyzden = 1 " . (($s == 1) ? "OR tyzden = 2 " : "") . "ORDER BY skratka ASC";
        $prac_q = MySQL_Query($prac_s);
        $sel = 1;
        if ($s == 1) {
            if ($prac_sviatok == 1)
                $sel = 1;
            else
                $sel = 6;
        }
        $over_s = "SELECT * FROM dochadzka WHERE zid = '" . $zid . "' AND dat = '" . $dat_db . "' ORDER BY id DESC LIMIT 0,1";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n == 1) {
            $over = MySQL_Fetch_Array($over_q);
            $sel = $over['pid'];
        }
        while ($prac = MySQL_Fetch_Array($prac_q)) {
            $xxx .= "<option value=\"" . $prac[id] . "\" style=\"background-color: #" . $prac[farba] . ";\"" . (($prac[id] == $sel) ? " selected" : "") . ">" . $prac[skratka] . "</option>";
        }
    } else {
        $prac_s = "SELECT * FROM praca " . (($s != 1) ? "WHERE tyzden < 2 " : "") . " ORDER BY skratka ASC";
        $prac_q = MySQL_Query($prac_s);
        if ($prac_vikend == 1)
            $sel = 1;
        else
            $sel = 6;
        if ($s == 1) {
            if ($prac_sviatok == 1)
                $sel = 1;
            else
                $sel = 6;
        }
        $over_s = "SELECT * FROM dochadzka WHERE zid = '" . $zid . "' AND dat = '" . $dat_db . "' ORDER BY id DESC LIMIT 0,1";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n == 1) {
            $over = MySQL_Fetch_Array($over_q);
            $sel = $over['pid'];
        }
        while ($prac = MySQL_Fetch_Array($prac_q)) {
            $xxx .= "<option value=\"" . $prac[id] . "\" style=\"background-color: #" . $prac[farba] . ";\"" . (($prac[id] == $sel) ? " selected" : "") . ">" . $prac[skratka] . "</option>";
        }
    }
    $ret = "<select name=\"doch_" . $zid . "_" . $den . "\" class=\"select\">";
    $ret .= $xxx;
    $ret .= "</select>";
    return $ret;
}

function dochadzka_sel_uzamk($zid, $den, $mes, $rok) {
    $dat = $den . "." . $mes . "." . $rok;
    $dat_db = date_conv_to_db($dat);
    $over_s = "SELECT praca.id,praca.skratka,praca.farba FROM dochadzka,praca WHERE dochadzka.zid = '" . $zid . "' AND dochadzka.dat = '" . $dat_db . "' AND praca.id = dochadzka.pid ";
    $over_q = MySQL_Query($over_s);
    $over = MySQL_Fetch_Array($over_q);
    $ret = "<font style=\"font-size: 14px; background-color: #" . $over['farba'] . ";\">&nbsp;" . $over['skratka'] . "&nbsp;</font>";
    return $ret;
}

function dochadzka_sel_uzamk_export($zid, $den, $mes, $rok) {
    $dat = $den . "." . $mes . "." . $rok;
    $dat_db = date_conv_to_db($dat);
    $over_s = "SELECT praca.id,praca.skratka,praca.farba FROM dochadzka,praca WHERE dochadzka.zid = '" . $zid . "' AND dochadzka.dat = '" . $dat_db . "' AND praca.id = dochadzka.pid ";
    $over_q = MySQL_Query($over_s);
    $over = MySQL_Fetch_Array($over_q);
    $ret[] = $over['skratka'];
    return $ret;
}

function docs_14($spolid) {
    global $user_id;
    $over_s = "SELECT admin FROM user WHERE id = '" . $user_id . "' ";
    $over_q = MySQL_Query($over_s);
    $over = MySQL_Fetch_Array($over_q);
    if ($over['admin'] == 1) {
        $subory_s = "SELECT * FROM mzdy_docs WHERE spolid = '" . $spolid . "' AND mesiac = '" . $_SESSION['doch_mes'] . "' AND rok = '" . $_SESSION['doch_rok'] . "' ORDER BY nazov ASC";
        $subory_q = MySQL_Query($subory_s);
        $subory_n = MySQL_Num_Rows($subory_q);
        if ($subory_n > 0) {
            echo "<b><u>" . preklad(125) . "</u></b>";
            echo "<table style=\"border: 1px #df5910 solid;\">\n";
            echo "<tr><td>#</td><td>" . preklad(66) . "</td><td>" . preklad(67) . "</td></tr>\n";
            $i = 1;
            while ($subory = MySQL_Fetch_Array($subory_q)) {
                echo "<tr><td>" . $i . "</td><td><a href=\"get_file_mzdy.php?did=" . $subory['id'] . "\">" . $subory['nazov'] . "</a></td><td>" . date_conv_to_view($subory['datum_pridania']) . "</td></tr>\n";
                $i++;
            }
            echo "</table>\n";
        }
        echo "<br />";
    }
}

function dochadzka() {
    echo "<h2>" . preklad(105) . "</h2>\n";
    global $user_id;
    $nac_s = "SELECT user.spolid,spolocnost.dtid,spolocnost.pracovny_vikend,spolocnost.pracovny_sviatok,spolocnost.zac_mesiac,zac_rok FROM user,spolocnost WHERE user.id = '" . $user_id . "' AND spolocnost.id = user.spolid ";
    $nac_q = MySQL_Query($nac_s);
    $nac = MySQL_Fetch_Array($nac_q);
    $spolid = $nac['spolid'];
    $prvy_y = $nac['zac_rok'];
    $prvy_m = $nac['zac_mesiac'];
    $now_y = Date("Y");
    $now_m = Date("n");
    //$now_m = 10;
    $now_d = Date("j");
    //$now_d = 1;

    if ((($prvy_m > $now_m) && ($prvy_y == $now_y)) || ($prvy_y > $now_y)) {
        echo preklad(130);
    } else {
        if ($now_m == 12) {
            $nasl_m = 1;
            $nasl_y = $now_y + 1;
        } else {
            $nasl_m = $now_m + 1;
            $nasl_y = $now_y;
        }

        $posl_y = $now_y;
        $posl_m = $now_m;

        if (Empty($_SESSION['doch_rok']))
            $_SESSION['doch_rok'] = $posl_y;
        if (Empty($_SESSION['doch_mes']))
            $_SESSION['doch_mes'] = $posl_m;

        if ($_SESSION['doch_rok'] < $prvy_y || $_SESSION['doch_rok'] > $posl_y) {
            $_SESSION['doch_rok'] = $posl_y;
        }
        if ($_SESSION['doch_rok'] == $prvy_y && $_SESSION['doch_mes'] < $prvy_m) {
            $_SESSION['doch_rok'] = $posl_y;
            $_SESSION['doch_mes'] = $posl_m;
        }
        if ($_SESSION['doch_rok'] == $posl_y && $_SESSION['doch_mes'] > $posl_m) {
            $_SESSION['doch_rok'] = $posl_y;
            $_SESSION['doch_mes'] = $posl_m;
        }

        echo "<table><tr><td>" . preklad(106) . "&nbsp;<select onChange=\"jm(this)\" size=\"1\">";
        for ($i = $now_y; $i >= $prvy_y; $i--) {
            if ($i == $prvy_y)
                $od = $prvy_m;
            else
                $od = 1;
            if ($i == $now_y)
                $to = $now_m;
            else
                $to = 12;
            for ($j = $to; $j >= $od; $j--) {
                $ov_s = "SELECT id FROM uzamknutie WHERE spolid = '" . $spolid . "' AND mesiac = '" . $j . "' AND rok = '" . $i . "' ";
                $ov_q = MySQL_Query($ov_s);
                $ov_n = MySQL_Num_Rows($ov_q);
                $mes_lang = $j + 109;
                echo "<option value=\"" . $j . "," . $i . "\"" . (($i == $_SESSION['doch_rok'] && $j == $_SESSION['doch_mes']) ? " selected" : "") . ">" . preklad($mes_lang) . " " . $i . (($ov_n > 0) ? "" : " *") . "</option>";
            }
        }
        echo "</select>\n</td><td>";
        $over_s = "SELECT id,typid FROM uzamknutie WHERE spolid = '" . $spolid . "' AND mesiac = '" . $_SESSION['doch_mes'] . "' AND rok = '" . $_SESSION['doch_rok'] . "' ";
        $over_q = MySQL_Query($over_s);
        $over_n = MySQL_Num_Rows($over_q);
        if ($over_n == 0) {
            echo "<form action=\"\" method=\"post\" name=\"odovzdanie\"><input type=\"hidden\" name=\"odovzdanie_doch\" value=\"1\"><input type=\"hidden\" name=\"odovzdanie_mes\" value=\"" . $_SESSION['doch_mes'] . "\"><input type=\"hidden\" name=\"odovzdanie_rok\" value=\"" . $_SESSION['doch_rok'] . "\"><input type=\"submit\" onclick=\"return confirmation();\" name=\"odovzd_doch_new\" value=\"" . preklad(107) . "\" class=\"submit_odovzdanie\">";
            //echo "</form>\n";
            echo "<script type=\"text/JavaScript\">\n<!--\nfunction confirmation()\n{\n	\n		var answer = confirm(\"" . preklad(108) . "\")\n		if (answer)\n		{\n			return true;\n		}\n		else\n		{\n			return false;\n		}\n	}\n//-->\n</script>";
        } else {
            $over = MySQL_Fetch_Array($over_q);
            echo "&nbsp;";
        }
        echo "</td></tr></table>\n";
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?zmen_doch=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
        echo "<br /><br />";

        if ($over_n > 0) {
            docs_14($spolid);
        }
        if ($over_n == 0) {
            if ($nac['dtid'] == 1)
                dochadzka_kalendar($spolid, $over_n);
            else
                dochadzka_zoznam($spolid, $over_n);
        }
        else {
            if ($over['typid'] == 1)
                dochadzka_kalendar($spolid, $over_n);
            else
                dochadzka_zoznam($spolid, $over_n);
        }
    }
}

function dochadzka_kalendar($spolid, $over_n) {
    global $user_id;
    $mesiac = $_SESSION['doch_mes'];
    $rok = $_SESSION['doch_rok'];
    $mesiac_time = mktime(0, 0, 0, $mesiac, 1, $rok);
    $pocet_dni = Date("t", $mesiac_time);

    $sviat_s = "SELECT * FROM sviatok WHERE mesiac = '" . $mesiac . "' AND rok = '" . $rok . "' ORDER BY den ASC";
    $sviat_q = MySQL_Query($sviat_s);
    $sv = Array();
    while ($sviat = MySQL_Fetch_Array($sviat_q)) {
        $sv[] = $sviat['den'];
    }
    //if ($over_n == 0)
    //echo "<form action=\"\" method=\"post\">\n";
    echo "<table cellpadding=\"1\" cellspacing=\"1\" class=\"tabulka_doch\">\n";
    echo "<tr class=\"nadpis\">";
    echo "<td>#</td><td align=\"left\">" . preklad(21) . "</td>";
    for ($i = 1; $i <= $pocet_dni; $i++) {
        $den_time = mktime(0, 0, 0, $mesiac, $i, $rok);
        $den_typ = Date("w", $den_time);
        if ($den_typ == 0)
            $den_typ = 7;
        echo "<td align=\"center\">$i</td>";
    }
    echo "<td align=\"left\">" . preklad(21) . "</td></tr>\n";
    echo "<tr>";
    echo "<td>&nbsp;</td><td align=\"left\">&nbsp;</td>";
    for ($i = 1; $i <= $pocet_dni; $i++) {
        $den_time = mktime(0, 0, 0, $mesiac, $i, $rok);
        $den_typ = Date("w", $den_time);
        if ($den_typ == 0)
            $den_typ = 7;

        if (In_Array($i, $sv)) {
            echo "<td align=\"center\" class=\"vikend\">" . preklad(124) . "</td>";
        } else {
            if ($den_typ == 6)
                echo "<td align=\"center\" class=\"vikend\">" . preklad(122) . "</td>";
            elseif ($den_typ == 7)
                echo "<td align=\"center\" class=\"vikend\">" . preklad(123) . "</td>";
            else
                echo "<td align=\"center\">&nbsp;</td>";
        }
    }
    echo "<td align=\"left\">&nbsp;</td></tr>\n";

    $spol_s = "SELECT * FROM spolocnost WHERE id = '" . $spolid . "' ";
    $spol_q = MySQL_Query($spol_s);
    $spol = MySQL_Fetch_Array($spol_q);
    $prac_vikend = $spol['pracovny_vikend'];
    $prac_sviatok = $spol['pracovny_sviatok'];
    $akt_dat = Date("Y-m-d");
    if ($over_n == 0)
        $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
    else
        $zam_s = "SELECT z.id,z.meno,z.priezvisko FROM dochadzka_historia,z WHERE dochadzka_historia.spolid = '" . $spolid . "' AND dochadzka_historia.rok = '" . $rok . "' AND dochadzka_historia.mesiac = '" . $mesiac . "' AND z.id = dochadzka_historia.zid ORDER BY z.priezvisko ASC";
    $zam_q = MySQL_Query($zam_s);
    $j = 1;
    while ($zam = MySQL_Fetch_Array($zam_q)) {
        echo "<tr class=\"zamestnanec\">";
        echo "<td>" . $j . "</td><td align=\"left\"><a href=\"?akc=3&akc2=2&zid=" . $zam['id'] . "\" class=\"a_kal_meno\">" . $zam['priezvisko'] . "&nbsp;" . $zam['meno'] . "</a></td>";
        for ($i = 1; $i <= $pocet_dni; $i++) {
            $den_time = mktime(0, 0, 0, $mesiac, $i, $rok);
            $den_typ = Date("w", $den_time);
            if ($den_typ == 0)
                $den_typ = 7;
            if (In_Array($i, $sv))
                $s = 1;
            else
                $s = 0;
            echo "<td align=\"center\" class=\"" . (($den_typ >= 6 || In_Array($i, $sv)) ? "vikend" : "den") . "\">" . (($over_n == 0) ? dochadzka_sel($den_typ, $zam['id'], $i, $mesiac, $rok, $prac_vikend, $s, $prac_sviatok) : dochadzka_sel_uzamk($zam['id'], $i, $mesiac, $rok) ) . "</td>";
        }
        echo "<td align=\"left\"><a href=\"?akc=3&akc2=2&zid=" . $zam['id'] . "\" class=\"a_kal_meno\">" . $zam['priezvisko'] . "&nbsp;" . $zam['meno'] . "</a></td></tr>\n";
        $j++;
    }

    echo "</table>\n";
    echo "<table>\n";
    $pozn_s = "SELECT text FROM dochadzka_text WHERE spolid = '" . $spolid . "' AND mesiac = '" . $mesiac . "' AND rok = '" . $rok . "' ORDER BY id DESC LIMIT 0,1";
    $pozn_q = MySQL_Query($pozn_s);
    $pozn = MySQL_Fetch_Array($pozn_q);
    if ($over_n == 0)
        echo "<tr><td valign=\"top\">" . preklad(101) . "</td><td valign=\"top\"><textarea name=\"doch_text\" rows=\"6\" cols=\"50\">" . $pozn['text'] . "</textarea></td><td valign=\"top\">";
    else
        echo "<tr><td valign=\"top\">" . preklad(101) . "</td><td valign=\"top\" style=\"width: 350px;\"><b>" . zalamovanie_na_vypis($pozn['text']) . "</b></td><td valign=\"top\">";
    $stlpcov = 2;
    $typy_s = "SELECT * FROM praca WHERE skratka != '' AND tyzden < 3 ORDER BY skratka ASC";
    $typy_q = MySQL_Query($typy_s);
    $typy_n = MySQL_Num_Rows($typy_q);
    $poc = Ceil($typy_n / $stlpcov);
    $i = 1;
    while ($typy = MySQL_Fetch_Array($typy_q)) {
        echo "<font style=\"background-color: #" . $typy['farba'] . ";\">&nbsp;" . $typy['skratka'] . " - " . $typy['nazov'] . "&nbsp;</font><br />\n";
        if ($i % $poc == 0 && $i != $typy_n)
            echo "</td><td valign=\"top\">";
        $i++;
    }
    echo "</td><tr>";
    echo "</table>\n";
    if ($over_n == 0)
        echo "<input type=\"hidden\" name=\"doch_kal\" value=\"1\" /><input type=\"submit\" name=\"doch_kal_new\" value=\"" . preklad(60) . "\" />";
    if ($over_n == 0)
        echo "</form>\n";
    echo "<br /><br />";
    if ($over_n == 0) {
        echo "<form action=\"\" method=\"post\">\n";
        echo "<u>" . preklad(109) . "</u><br />";
        for ($i = 1; $i <= 5; $i++) {
            echo "<select name=\"kto_" . $i . "\"><option value=\"0\">" . preklad(50) . "</option>";
            $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
            $zam_q = MySQL_Query($zam_s);
            while ($zam = MySQL_Fetch_Array($zam_q)) {
                echo "<option value=\"" . $zam['id'] . "\">" . $zam['priezvisko'] . " " . $zam['meno'] . "</option>";
            }
            echo "</select> " . preklad(99) . "<select name=\"od_" . $i . "\">";
            for ($j = 1; $j <= $pocet_dni; $j++) {
                echo "<option value=\"" . $j . "\">" . $j . "</option>";
            }
            echo "</select> " . preklad(100) . "<select name=\"do_" . $i . "\">";
            for ($j = 1; $j <= $pocet_dni; $j++) {
                echo "<option value=\"" . $j . "\">" . $j . "</option>";
            }
            echo "</select> <select name=\"co_" . $i . "\">";
            $praca_s = "SELECT * FROM praca WHERE tyzden = 1 ORDER BY skratka ASC";
            $praca_q = MySQL_Query($praca_s);
            while ($praca = MySQL_Fetch_Array($praca_q)) {
                echo "<option value=\"" . $praca['id'] . "\" style=\"background-color: #" . $praca['farba'] . ";\">" . $praca['skratka'] . " - " . $praca['nazov'] . "</option>";
            }
            echo "</select><br />\n";
        }
        echo "<input type=\"hidden\" name=\"doch_kal2\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" />";
        echo "</form>\n";
    }
}

function dochadzka_kalendar_sent($ajOdovzdat) {
    global $user_id;
    $nac_s = "SELECT spolid FROM user WHERE id = '" . $user_id . "' ";
    $nac_q = MySQL_Query($nac_s);
    $nac = MySQL_Fetch_Array($nac_q);
    $spolid = $nac['spolid'];
    $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
    $zam_q = MySQL_Query($zam_s);
    $rok = $_SESSION['doch_rok'];
    $mes = $_SESSION['doch_mes'];
    $dat_zac = "1." . $mes . "." . $rok;
    $dat_kon = "31." . $mes . "." . $rok;
    $mesiac_time = mktime(0, 0, 0, $mes, 1, $rok);
    $pocet_dni = Date("t", $mesiac_time);
    while ($zam = MySQL_Fetch_Array($zam_q)) {
        $zmaz_d = "DELETE FROM dochadzka WHERE zid = '" . $zam['id'] . "' AND dat >= '" . date_conv_to_db($dat_zac) . "' AND dat <= '" . date_conv_to_db($dat_kon) . "' ";
        $zmaz_q = MySQL_Query($zmaz_d);
        for ($i = 1; $i <= $pocet_dni; $i++) {
            $premenna = "doch_" . $zam['id'] . "_" . $i;
            $co = $_POST[$premenna];
            $dat = $i . "." . $mes . "." . $rok;
            $uloz_i = "INSERT INTO dochadzka (id, zid, dat, pid) VALUES (NULL, '" . $zam['id'] . "', '" . date_conv_to_db($dat) . "', '" . $co . "')";
            $uloz_q = MySQL_Query($uloz_i);
        }
    }
    $text_ok = Trim(HtmlSpecialChars($_POST['doch_text'], ENT_QUOTES));
    $zmaz_d = "DELETE FROM dochadzka_text WHERE spolid = '" . $spolid . "' AND mesiac = '" . $mes . "' AND rok = '" . $rok . "' ";
    $zmaz_q = MySQL_Query($zmaz_d);
    if (!Empty($text_ok)) {
        $uloz_i = "INSERT INTO dochadzka_text (id, mesiac, rok, spolid,text) VALUES (NULL, '" . $mes . "', '" . $rok . "', '" . $spolid . "', '" . $text_ok . "')";
        $uloz_q = MySQL_Query($uloz_i);
    }
    if ($ajOdovzdat == 0) {
        Header("Location: ?akc=4");
        exit();
    }
}

function dochadzka_kalendar_sent2() {
    for ($i = 1; $i <= 5; $i++) {
        $prem_kto = "kto_" . $i;
        $prem_od = "od_" . $i;
        $prem_do = "do_" . $i;
        $prem_co = "co_" . $i;
        if ($_POST[$prem_kto] > 0) {
            if ($_POST[$prem_do] >= $_POST[$prem_od]) {
                for ($j = $_POST[$prem_od]; $j <= $_POST[$prem_do]; $j++) {
                    $rok = $_SESSION['doch_rok'];
                    $mes = $_SESSION['doch_mes'];
                    $dat = $j . "." . $mes . "." . $rok;
                    $zmaz_d = "DELETE FROM dochadzka WHERE zid = '" . $_POST[$prem_kto] . "' AND dat = '" . date_conv_to_db($dat) . "' ";
                    $zmaz_q = MySQL_Query($zmaz_d);
                    $uloz_i = "INSERT INTO dochadzka (id, zid, dat, pid) VALUES (NULL, '" . $_POST[$prem_kto] . "', '" . date_conv_to_db($dat) . "', '" . $_POST[$prem_co] . "')";
                    $uloz_q = MySQL_Query($uloz_i);
                }
            }
        }
    }
    Header("Location: ?akc=4");
    exit();
}

function dochadzka_neodoslana($den_typ, $zid, $den, $mes, $rok, $prac_vikend, $s, $prac_sviatok) {
    $dat = $den . "." . $mes . "." . $rok;
    $dat_db = date_conv_to_db($dat);
    if ($den_typ < 6) {
        $prac_s = "SELECT * FROM praca WHERE tyzden = 1 " . (($s == 1) ? "OR tyzden = 2 " : "") . "ORDER BY id ASC";
        $prac_q = MySQL_Query($prac_s);
        $sel = 1;
        if ($s == 1) {
            if ($prac_sviatok == 1)
                $sel = 1;
            else
                $sel = 6;
        }
    }
    else {
        $prac_s = "SELECT * FROM praca " . (($s != 1) ? "WHERE tyzden <> 2 " : "") . " ORDER BY tyzden,id ASC";
        $prac_q = MySQL_Query($prac_s);
        if ($prac_vikend == 1)
            $sel = 1;
        else
            $sel = 6;
        if ($s == 1) {
            if ($prac_sviatok == 1)
                $sel = 1;
            else
                $sel = 6;
        }
    }
    return $sel;
}

function dochadzka_odovzdat_sent() {
    $datcas = Date("Y-m-d H:i:s");
    global $user_id;
    $ov_s = "SELECT spolid FROM user WHERE user.id = '" . $user_id . "'";
    $ov_q = MySQL_Query($ov_s);
    $ov = MySQL_Fetch_Array($ov_q);
    $spolid = $ov['spolid'];
    $nastav_s = "SELECT dtid,pracovny_vikend,pracovny_sviatok FROM spolocnost WHERE id = '" . $spolid . "' ";
    $nastav_q = MySQL_Query($nastav_s);
    $nastav = MySQL_Fetch_Array($nastav_q);
    $mes_ok = IntVal($_POST['odovzdanie_mes']);
    $rok_ok = IntVal($_POST['odovzdanie_rok']);
    $ov2_s = "SELECT id FROM uzamknutie WHERE mesiac = '" . $mes_ok . "' AND rok = '" . $rok_ok . "' AND spolid = '" . $spolid . "' ";
    $ov2_q = MySQL_Query($ov2_s);
    $ov2_n = MySQL_Num_Rows($ov2_q);
    if ($ov2_n == 0) {
        if ($nastav['dtid'] == 1) {
            $sviat_s = "SELECT * FROM sviatok WHERE mesiac = '" . $mes_ok . "' AND rok = '" . $rok_ok . "' ORDER BY den ASC";
            $sviat_q = MySQL_Query($sviat_s);
            $sv = Array();
            while ($sviat = MySQL_Fetch_Array($sviat_q)) {
                $sv[] = $sviat['den'];
            }
            $pocet_dni = cal_days_in_month(CAL_GREGORIAN, $mes_ok, $rok_ok);
            $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
            $zam_q = MySQL_Query($zam_s);
            while ($zam = MySQL_Fetch_Array($zam_q)) {
                for ($i = 1; $i <= $pocet_dni; $i++) {
                    $den_time = mktime(0, 0, 0, $mes_ok, $i, $rok_ok);
                    $den_typ = Date("w", $den_time);
                    if ($den_typ == 0)
                        $den_typ = 7;
                    if (In_Array($i, $sv))
                        $s = 1;
                    else
                        $s = 0;
                    $d = $i . "." . $mes_ok . "." . $rok_ok;
                    $dat = date_conv_to_db("$d");
                    $ov3_s = "SELECT id FROM dochadzka WHERE zid = '" . $zam['id'] . "' AND dat = '" . $dat . "' ";
                    $ov3_q = MySQL_Query($ov3_s);
                    $ov3_n = MySQL_Num_Rows($ov3_q);
                    if ($ov3_n == 0) {
                        $x = dochadzka_neodoslana($den_typ, $zam['id'], $i, $mes_ok, $rok_ok, $nastav['pracovny_vikend'], $s, $nastav['pracovny_sviatok']);
                        $pridaj_i = "INSERT INTO dochadzka (id, zid, dat, pid) VALUES (NULL, '" . $zam['id'] . "','" . $dat . "', '" . $x . "')";
                        $pridaj_q = MySQL_Query($pridaj_i);
                    }
                }
                $historia_i = "INSERT INTO dochadzka_historia (id, rok, mesiac, zid, spolid) VALUES (NULL, '" . $rok_ok . "', '" . $mes_ok . "', '" . $zam['id'] . "', '" . $spolid . "')";
                $historia_q = MySQL_Query($historia_i);
            }
        } else {
            $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
            $zam_q = MySQL_Query($zam_s);
            while ($zam = MySQL_Fetch_Array($zam_q)) {
                $historia_i = "INSERT INTO dochadzka_historia (id, rok, mesiac, zid, spolid) VALUES (NULL, '" . $rok_ok . "', '" . $mes_ok . "', '" . $zam['id'] . "', '" . $spolid . "')";
                $historia_q = MySQL_Query($historia_i);
            }
        }
        $uzamknutie_i = "INSERT INTO uzamknutie (id, mesiac, rok, spolid, uid, datcas, typid) VALUES (NULL, '" . $mes_ok . "', '" . $rok_ok . "', '" . $spolid . "', '" . $user_id . "', '" . $datcas . "', '" . $nastav['dtid'] . "')";
        $uzamknutie_q = MySQL_Query($uzamknutie_i);

        $starost_s = "SELECT spolocnost.nazov,spolocnost.uid,user.mail FROM spolocnost,user WHERE spolocnost.id = '" . $spolid . "' AND user.id = spolocnost.uid ";
        $starost_q = MySQL_Query($starost_s);
        $starost = MySQL_Fetch_Array($starost_q);
        $komu = $starost['mail'];
        $predmet = "mzdy.bmbleitner.sk";
        $text = "Spoločnosť " . $starost['nazov'] . " odovzdala dochádzku za " . mesiac_sk($mes_ok) . " " . $rok_ok;

        poslat_email($komu, $predmet, $text);
    }
    Header("Location: ?akc=4");
    exit();
}

function dochadzka_zoznam($spolid, $over_n) {
    global $user_id;
    $mesiac = $_SESSION['doch_mes'];
    $rok = $_SESSION['doch_rok'];
    $mesiac_time = mktime(0, 0, 0, $mesiac, 1, $rok);
    $pocet_dni = Date("t", $mesiac_time);
    if ($over_n == 0) {
        echo "</form>\n";
        echo "<form action=\"\" method=\"post\">\n";
        echo "<u>" . preklad(98) . "</u><br />";
        for ($i = 1; $i <= 5; $i++) {
            echo "<select name=\"kto_" . $i . "\"><option value=\"0\">" . preklad(50) . "</option>";
            $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
            $zam_q = MySQL_Query($zam_s);
            while ($zam = MySQL_Fetch_Array($zam_q)) {
                echo "<option value=\"" . $zam['id'] . "\">" . $zam['priezvisko'] . " " . $zam['meno'] . "</option>";
            }
            echo "</select> " . preklad(99) . "<select name=\"od_" . $i . "\">";
            for ($j = 1; $j <= $pocet_dni; $j++) {
                echo "<option value=\"" . $j . "\">" . $j . "</option>";
            }
            echo "</select> " . preklad(100) . "<select name=\"do_" . $i . "\">";
            for ($j = 1; $j <= $pocet_dni; $j++) {
                echo "<option value=\"" . $j . "\">" . $j . "</option>";
            }
            echo "</select> <select name=\"co_" . $i . "\">";
            $praca_s = "SELECT * FROM praca WHERE skratka != '' AND id != 1 ORDER BY skratka ASC";
            $praca_q = MySQL_Query($praca_s);
            while ($praca = MySQL_Fetch_Array($praca_q)) {
                echo "<option value=\"" . $praca['id'] . "\" style=\"background-color: #" . $praca['farba'] . ";\">" . $praca['skratka'] . " - " . preklad($praca['jazyk_id']) . "</option>";
            }
            echo "<input type=\"text\" name=\"text_" . $i . "\" />";
            echo "</select><br />\n";
        }
    }
    echo "<table>\n";
    $pozn_s = "SELECT text FROM dochadzka_text WHERE spolid = '" . $spolid . "' AND mesiac = '" . $mesiac . "' AND rok = '" . $rok . "' ORDER BY id DESC LIMIT 0,1";
    $pozn_q = MySQL_Query($pozn_s);
    $pozn = MySQL_Fetch_Array($pozn_q);
    if ($over_n == 0)
        echo "<tr><td valign=\"top\">" . preklad(101) . "</td><td valign=\"top\"><textarea name=\"doch_text\" rows=\"6\" cols=\"50\">" . $pozn['text'] . "</textarea></td><td valign=\"top\">";
    else
        echo "<tr><td valign=\"top\">" . preklad(101) . "</td><td valign=\"top\" style=\"width: 350px;\"><b>" . zalamovanie_na_vypis($pozn['text']) . "</b></td><td valign=\"top\">";
    $stlpcov = 2;
    $typy_s = "SELECT * FROM praca WHERE skratka != '' AND id != 1 ORDER BY skratka ASC";
    $typy_q = MySQL_Query($typy_s);
    $typy_n = MySQL_Num_Rows($typy_q);
    $poc = Ceil($typy_n / $stlpcov);
    $i = 1;
    while ($typy = MySQL_Fetch_Array($typy_q)) {
        echo "<font style=\"background-color: #" . $typy['farba'] . ";\">&nbsp;" . $typy['skratka'] . " - " . preklad($typy['jazyk_id']) . "&nbsp;</font><br />\n";
        if ($i % $poc == 0 && $i != $typy_n)
            echo "</td><td valign=\"top\">";
        $i++;
    }
    echo "</td><tr>";
    echo "</table>\n";
    if ($over_n == 0) {
        echo "<input type=\"hidden\" name=\"doch_zoznam\" value=\"1\" /><input type=\"submit\" value=\"" . preklad(60) . "\" />";
        echo "</form>\n";
    }
    echo "<br /><br />\n";

    $ord = Array("z.priezvisko", "dochadzka_nepritomnost.den_od", "dochadzka_nepritomnost.den_do", "praca.skratka");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }

    echo "<u>" . preklad(102) . "</u><br />\n";
    echo "<table>\n";
    echo "<tr><td>#</td><td><a href=\"?akc=4&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(9) . "</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=4&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(99) . "</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=4&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(100) . "</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=4&order=3&asc=" . (($order_x == 3 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(103) . "</a>" . (($order_x == 3) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>&nbsp;</td></tr>\n";
    $neprit_s = "SELECT dochadzka_nepritomnost.id,dochadzka_nepritomnost.den_od,dochadzka_nepritomnost.den_do,dochadzka_nepritomnost.pid,dochadzka_nepritomnost.text,z.meno,z.priezvisko,praca.skratka,praca.farba FROM dochadzka_nepritomnost,z,praca WHERE dochadzka_nepritomnost.spolid = '" . $spolid . "' AND dochadzka_nepritomnost.rok = '" . $rok . "' AND dochadzka_nepritomnost.mesiac = '" . $mesiac . "' AND z.id = dochadzka_nepritomnost.zid AND praca.id = dochadzka_nepritomnost.pid ORDER BY " . $order_ok . " " . $asc_ok;
    $neprit_q = MySQL_Query($neprit_s);
    $i = 1;
    while ($neprit = MySQL_Fetch_Array($neprit_q)) {
        echo "<tr><td>" . $i . "</td><td>" . $neprit['priezvisko'] . " " . $neprit['meno'] . " &nbsp;</td><td><b>" . $neprit['den_od'] . "</b>." . $mesiac . "." . $rok . "</td><td><b>" . $neprit['den_do'] . "</b>." . $mesiac . "." . $rok . "</td><td><font style=\"background-color: #" . $neprit['farba'] . ";\">&nbsp;" . $neprit['skratka'] . "&nbsp;</font>" . (($neprit['pid'] == 15) ? " - " . $neprit['text'] : "") . "</td><td>" . (($over_n == 0) ? "<a href=\"?neprit_zmaz=1&nid=" . $neprit['id'] . "\">" . preklad(104) . "</a>" : "&nbsp;") . "</td></tr>\n";
        $i++;
    }
    echo "</table>\n";
}

function nepritomnost_zmazat() {
    global $user_id;
    $nac_s = "SELECT spolid FROM user WHERE id = '" . $user_id . "' ";
    $nac_q = MySQL_Query($nac_s);
    $nac = MySQL_Fetch_Array($nac_q);
    $spolid = $nac['spolid'];
    $nid_ok = IntVal($_GET['nid']);
    $over_s = "SELECT spolid,rok,mesiac FROM dochadzka_nepritomnost WHERE id = '" . $nid_ok . "' ";
    $over_q = MySQL_Query($over_s);
    $over = MySQL_Fetch_Array($over_q);
    if ($over['spolid'] == $spolid) {
        $over2_s = "SELECT id FROM uzamknutie WHERE mesiac = '" . $over['mesiac'] . "' AND rok = '" . $over['rok'] . "' AND spolid = '" . $spolid . "' ";
        $over2_q = MySQL_Query($over2_s);
        $over2_n = MySQL_Num_Rows($over2_q);
        if ($over2_n == 0) {
            $zmaz_d = "DELETE FROM dochadzka_nepritomnost WHERE id = '" . $nid_ok . "' AND spolid = '" . $spolid . "' ";
            $zmaz_q = MySQL_Query($zmaz_d);
        }
    }
    Header("Location: ?akc=4");
    exit();
}

function dochadzka_zoznam_sent() {
    global $user_id;
    $nac_s = "SELECT spolid FROM user WHERE id = '" . $user_id . "' ";
    $nac_q = MySQL_Query($nac_s);
    $nac = MySQL_Fetch_Array($nac_q);
    $spolid = $nac['spolid'];
    $rok = $_SESSION['doch_rok'];
    $mes = $_SESSION['doch_mes'];
    for ($i = 1; $i <= 5; $i++) {
        $prem_kto = "kto_" . $i;
        $prem_od = "od_" . $i;
        $prem_do = "do_" . $i;
        $prem_co = "co_" . $i;
        $prem_text = "text_" . $i;
        if ($_POST[$prem_kto] > 0) {
            if ($_POST[$prem_do] >= $_POST[$prem_od]) {
                $kto_ok = $_POST[$prem_kto];
                $od_ok = $_POST[$prem_od];
                $do_ok = $_POST[$prem_do];
                $co_ok = $_POST[$prem_co];
                if ($co_ok == 15)
                    $text2_ok = Trim(HtmlSpecialChars($_POST[$prem_text], ENT_QUOTES));
                else
                    $text2_ok = "";
                $uloz_i = "INSERT INTO dochadzka_nepritomnost (id, zid, spolid, rok, mesiac, den_od, den_do, pid, text) VALUES (NULL, '" . $kto_ok . "', '" . $spolid . "', '" . $rok . "', '" . $mes . "', '" . $od_ok . "', '" . $do_ok . "', '" . $co_ok . "', '" . $text2_ok . "')";
                $uloz_q = MySQL_Query($uloz_i);
            }
        }
    }
    $text_ok = Trim(HtmlSpecialChars($_POST['doch_text'], ENT_QUOTES));
    $zmaz_d = "DELETE FROM dochadzka_text WHERE spolid = '" . $spolid . "' AND mesiac = '" . $mes . "' AND rok = '" . $rok . "' ";
    $zmaz_q = MySQL_Query($zmaz_d);
    if (!Empty($text_ok)) {
        $uloz2_i = "INSERT INTO dochadzka_text (id, mesiac, rok, spolid,text) VALUES (NULL, '" . $mes . "', '" . $rok . "', '" . $spolid . "', '" . $text_ok . "')";
        $uloz2_q = MySQL_Query($uloz2_i);
    }
    Header("Location: ?akc=4");
    exit();
}

function zmen_doch($mes, $rok) {
    $_SESSION['doch_rok'] = $rok;
    $_SESSION['doch_mes'] = $mes;
    Header("Location: ?akc=4");
    exit();
}

function kalendar() {
    echo "<h2>Kalendár</h2>\n";
    echo "spoločnosť: <select onChange=\"jm(this)\" size=\"1\"><option value=\"0\">- - - vyberte - - -</option>";
    $spols_s = "SELECT * FROM spolocnost ORDER BY nazov ASC";
    $spols_q = MySQL_Query($spols_s);
    while ($spols = MySQL_Fetch_Array($spols_q)) {
        echo "<option value=\"" . $spols['id'] . "\"" . (($spols['id'] == $_SESSION['kalendar']) ? " selected" : "") . ">" . $spols['nazov'] . "</option>";
    }
    echo "</select>\n";
    echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?zmen_kal=1&spolid=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
    echo "<br />";

    if (!Empty($_SESSION['kalendar_rok']))
        $rok = $_SESSION['kalendar_rok'];
    else
        $rok = Date("Y");
    echo "zobraziť rok: <select onChange=\"ja(this)\" size=\"1\">";
    $prvy_rok = 2009;
    $aktual_rok = Date("Y");
    $posled_rok = $aktual_rok + 1;
    for ($i = $prvy_rok; $i <= $posled_rok; $i++) {
        echo "<option value=\"" . $i . "\"" . (($i == $rok) ? " selected" : "") . ">" . $i . "</option>";
    }
    echo "</select>\n";
    echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction ja(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?zmen_kal_rok=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
    echo "<br /><br />";

    if (!Empty($_SESSION['kalendar'])) {
        $g = "009900";
        $r = "990000";
        echo "<form action=\"\" method=\"post\" name=\"formular\">\n";
        echo "<div style=\"padding:5px;margin:5px;background:#eee;\">";
        echo "<b>pridať dátum odovzdania</b><br />";
        echo "<table>\n";
        echo "<tr><td>\n";
        echo "<font style=\"color: #" . $g . ";\">dochádzky:</font>\n</td><td>\n<select name=\"den_k\"><option value=\"\"> - </option>";
        for ($i = 1; $i <= 31; $i++) {
            echo "<option value=\"" . $i . "\">" . $i . "</option>";
        }
        echo "</select>\n";
        echo "<select name=\"mesiac_k\"><option value=\"\"> - - - </option>";
        $mes_s = "SELECT * FROM mesiac ORDER BY id ASC";
        $mes_q = MySQL_Query($mes_s);
        while ($mes = MySQL_Fetch_Array($mes_q)) {
            echo "<option value=\"" . $mes['id'] . "\">" . $mes['nazov'] . "</option>";
        }
        echo "</select>\n</td></tr>\n";
        echo "<tr><td>\n";
        echo "<font style=\"color: #" . $r . ";\">spracovyných miezd:</font>\n</td><td>\n<select name=\"den_b\"><option value=\"\"> - </option>";
        for ($i = 1; $i <= 31; $i++) {
            echo "<option value=\"" . $i . "\">" . $i . "</option>";
        }
        echo "</select>\n";
        echo "<select name=\"mesiac_b\"><option value=\"\"> - - - </option>";
        $mes_s = "SELECT * FROM mesiac ORDER BY id ASC";
        $mes_q = MySQL_Query($mes_s);
        while ($mes = MySQL_Fetch_Array($mes_q)) {
            echo "<option value=\"" . $mes['id'] . "\">" . $mes['nazov'] . "</option>";
        }
        echo "</select></td></tr>\n";
        echo "</table>";
        echo "<input type=\"hidden\" name=\"kalendar_pridat\" value=\"1\"><input type=\"submit\" value=\"pridaj\">";
        echo "</div>";
        echo "</form>\n";
        echo "<br />\n";
        echo "<b>Kalendár roku " . $rok . ":</b>\n";
        echo "<br /><br />\n";
        $kalendar_s = "SELECT kalendar.id,kalendar.den,kalendar.dochadzka,mesiac.nazov FROM kalendar,mesiac WHERE kalendar.rok = '" . $rok . "' AND kalendar.spolid = '" . $_SESSION['kalendar'] . "' AND mesiac.id = kalendar.mesiac ORDER BY kalendar.mesiac,kalendar.den ASC";
        $kalendar_q = MySQL_Query($kalendar_s);
        while ($kalendar = MySQL_Fetch_Array($kalendar_q)) {
            echo $kalendar['den'] . ". " . $kalendar['nazov'] . " <a href=\"?kalendar_del=1&k=" . $kalendar['id'] . "\">x</a> - " . (($kalendar['dochadzka'] == 1) ? "<font style=\"color: #" . $g . ";\">odovzdanie dochádzky</font>" : "<font style=\"color: #" . $r . ";\">odovzdanie spracovyných miezd</font>") . "<br />\n";
        }
    }
}

function kalendar_uloz() {
    if (!Empty($_POST['den_k']) && !Empty($_POST['mesiac_k'])) {
        $den_ok = IntVal($_POST['den_k']);
        $mesiac_ok = IntVal($_POST['mesiac_k']);
        if ($den_ok > 0 && $mesiac_ok > 0) {
            if (!Empty($_SESSION['kalendar_rok']))
                $rok_ok = $_SESSION['kalendar_rok'];
            else
                $rok_ok = Date("Y");

            $pocet_dni = cal_days_in_month(CAL_GREGORIAN, $mesiac_ok, $rok_ok);

            if ($den_ok <= $pocet_dni) {
                if ($mesiac_ok == 1) {
                    $m_posun = 12;
                    $r_posun = $rok_ok - 1;
                    $d_posun = $den_ok;
                } else {
                    $m_posun = $mesiac_ok - 1;
                    $r_posun = $rok_ok;
                    $d_posun = $den_ok;
                }

                $d_akt = Date(j);
                $m_akt = Date(n);

                $over_s = "SELECT id,typid FROM uzamknutie WHERE spolid = '" . $_SESSION['kalendar'] . "' AND mesiac = '" . $m_posun . "' AND rok = '" . $r_posun . "' ";
                $over_q = MySQL_Query($over_s);
                $over_n = MySQL_Num_Rows($over_q);
                if (($over_n > 0) && ($m_akt == $mesiac_ok) && ($d_akt <= $den_ok)) {
                    $over = MySQL_Fetch_Array($over_q);

                    $zmaz_d = "DELETE FROM uzamknutie WHERE id = '" . $over['id'] . "' ";
                    $zmaz_q = MySQl_Query($zmaz_d);

                    $zmaz2_d = "DELETE FROM dochadzka_historia WHERE rok = '" . $r_posun . "' AND mesiac = '" . $m_posun . "' AND spolid = '" . $_SESSION['kalendar'] . "' ";
                    $zmaz2_q = MySQl_Query($zmaz2_d);
                }

                $dat = $den_ok . "." . $mesiac_ok . "." . $rok_ok;
                $dat_ok = date_conv_to_db($dat);
                $kal_d = "DELETE FROM kalendar WHERE spolid = '" . $_SESSION['kalendar'] . "' AND mesiac = '" . $mesiac_ok . "' AND rok = '" . $rok_ok . "' AND dochadzka = 1";
                $kal_q = MySQL_Query($kal_d);
                $kalendar_i = "INSERT INTO kalendar (id, spolid, den, mesiac, rok, datum, dochadzka) VALUES (NULL, '" . $_SESSION['kalendar'] . "', '" . $den_ok . "','" . $mesiac_ok . "','" . $rok_ok . "', '" . $dat_ok . "', 1) ";
                $kalendar_q = MySQL_Query($kalendar_i);
            }
        }
    }
    if (!Empty($_POST['den_b']) && !Empty($_POST['mesiac_b'])) {
        $den_ok = IntVal($_POST['den_b']);
        $mesiac_ok = IntVal($_POST['mesiac_b']);
        if ($den_ok > 0 && $mesiac_ok > 0) {
            if (!Empty($_SESSION['kalendar_rok']))
                $rok_ok = $_SESSION['kalendar_rok'];
            else
                $rok_ok = Date("Y");

            $pocet_dni = cal_days_in_month(CAL_GREGORIAN, $mesiac_ok, $rok_ok);

            if ($den_ok <= $pocet_dni) {
                $dat = $den_ok . "." . $mesiac_ok . "." . $rok_ok;
                $dat_ok = date_conv_to_db($dat);
                $kal_d = "DELETE FROM kalendar WHERE spolid = '" . $_SESSION['kalendar'] . "' AND mesiac = '" . $mesiac_ok . "' AND rok = '" . $rok_ok . "' AND dochadzka = 2";
                $kal_q = MySQL_Query($kal_d);
                $kalendar_i = "INSERT INTO kalendar (id, spolid, den, mesiac, rok, datum, dochadzka) VALUES (NULL, '" . $_SESSION['kalendar'] . "', '" . $den_ok . "','" . $mesiac_ok . "','" . $rok_ok . "', '" . $dat_ok . "', 2) ";
                $kalendar_q = MySQL_Query($kalendar_i);
            }
        }
    }
    Header("Location: ?akc=8");
    exit();
}

function zmen_kal($spolid) {
    $_SESSION['kalendar'] = $spolid;
    Header("Location: ?akc=8");
    exit();
}

function zmen_kal_rok($zobraz) {
    $_SESSION['kalendar_rok'] = $zobraz;
    Header("Location: ?akc=8");
    exit();
}

function uvod() {
    global $user_id, $zedko;
    $about_user_s = "SELECT * FROM user WHERE id = '" . $user_id . "' ";
    $about_user_q = MySQL_Query($about_user_s);
    $about_user = MySQL_Fetch_Array($about_user_q);
    if ($zedko == 0) {
        if ($about_user['spolid'] == 0) {
            if ($about_user['admin'] == 1) {
                echo "";
            } else {
                echo "<br />\n";
                echo "<b><u>Nespracované dokumenty - spoločnosti</u></b><br />\n";
                $nesprac_s = "SELECT spol_docs.id,spol_docs.nazov,spol_docs.datum_pridania,spolocnost.nazov AS spol_nazov FROM spol_docs,spolocnost WHERE spol_docs.spracovat = 1 AND spolocnost.id = spol_docs.spolid AND (";
                $spols_s = "SELECT id FROM spolocnost WHERE uid = '" . $user_id . "' ORDER BY id ASC";
                $spols_q = MySQL_Query($spols_s);
                $spols_n = MySQL_Num_Rows($spols_q);
                if ($spols_n > 0) {
                    $i = 1;
                    while ($spols = MySQL_Fetch_Array($spols_q)) {
                        if ($i != 1)
                            $nesprac_s .= "OR";
                        $nesprac_s .= " spol_docs.spolid = '" . $spols['id'] . "' ";
                        $i++;
                    }
                }
                else {
                    $nesprac_s .= " spol_docs.spolid = 0 ";
                }
                $nesprac_s .= ") ORDER BY spol_docs.id ASC";
                $nesprac_q = MySQL_Query($nesprac_s);
                echo "<table>\n";
                echo "<tr><td>#</td><td>Spoločnosť:</td><td>Dokument:</td><td>Dátum pridania:</td><td>&nbsp;</td></tr>\n";
                $i = 1;
                while ($nesprac = MySQL_Fetch_Array($nesprac_q)) {
                    echo "<tr><td>" . $i . "</td><td>" . $nesprac['spol_nazov'] . "</td><td><a href=\"get_file_spol.php?did=" . $nesprac['id'] . "\">" . $nesprac['nazov'] . "</a></td><td>" . date_conv_to_view($nesprac['datum_pridania']) . "</td><td><a href=\"?spracovane=1&co=1&did=" . $nesprac['id'] . "\">označiť ako spracované</a></td></tr>\n";
                    $i++;
                }
                echo "</table>\n";
                echo "<br /><br />\n";

                echo "<b><u>Nespracované dokumenty - zamestnanci</u></b><br />\n";
                $nesprac_s = "SELECT z_docs.id,z_docs.nazov,z_docs.datum_pridania,z_docs.zid,z.spolid,z.meno,z.priezvisko,spolocnost.nazov AS spol_nazov FROM z_docs,z,spolocnost WHERE z_docs.spracovat = 1 AND z.id = z_docs.zid AND spolocnost.id = z.spolid AND (";
                $spols_s = "SELECT id FROM spolocnost WHERE uid = '" . $user_id . "' ORDER BY id ASC";
                $spols_q = MySQL_Query($spols_s);
                $spols_n = MySQL_Num_Rows($spols_q);
                if ($spols_n > 0) {
                    $i = 1;
                    while ($spols = MySQL_Fetch_Array($spols_q)) {
                        if ($i != 1)
                            $nesprac_s .= "OR";
                        $nesprac_s .= " z.spolid = '" . $spols['id'] . "' ";
                        $i++;
                    }
                }
                else {
                    $nesprac_s .= " spolid = 0 ";
                }
                $nesprac_s .= ") ORDER BY z_docs.id ASC";
                $nesprac_q = MySQL_Query($nesprac_s);
                echo "<table>\n";
                echo "<tr><td>#</td><td>Zamestnanec:</td><td>Dokument:</td><td>Dátum pridania:</td><td>&nbsp;</td></tr>\n";
                $i = 1;
                while ($nesprac = MySQL_Fetch_Array($nesprac_q)) {
                    echo "<tr><td>" . $i . "</td><td>" . $nesprac['priezvisko'] . " " . $nesprac['meno'] . " (" . $nesprac['spol_nazov'] . ")</td><td><a href=\"get_file.php?did=" . $nesprac['id'] . "\">" . $nesprac['nazov'] . "</a></td><td>" . date_conv_to_view($nesprac['datum_pridania']) . "</td><td><a href=\"?spracovane=1&co=2&did=" . $nesprac['id'] . "\">označiť ako spracované</a></td></tr>\n";
                    $i++;
                }
                echo "</table>\n";
            }
        } else {
            $y = Date("Y");
            $m = Date("n");
            $d = Date("j");
            $dat = Date("Y-m-d");
            $akc[1] = preklad(133) . " ";
            $akc[2] = preklad(134) . " ";
            $akcie_s = "SELECT * FROM kalendar WHERE datum >= '" . $dat . "' AND spolid = '" . $about_user['spolid'] . "' ORDER BY datum ASC LIMIT 0,2";
            $akcie_q = MySQL_Query($akcie_s);
            echo "<table>\n";
            echo "<tr><td>&nbsp;</td></tr>";
            while ($akcie = MySQL_Fetch_Array($akcie_q)) {
                $num = $akcie['dochadzka'];
                $mes_pred = $akcie['mesiac'] - 1;
                echo "<tr><td>" . $akc[$num] . " " . preklad($mes_pred + 109) . ": <b>" . date_conv_to_view($akcie['datum']) . "</b></td></tr>";
                //echo "<tr><td>".$akc[$num]." ".mesiac_sk ($mes_pred).": <b>".date_conv_to_view($akcie['datum'])."</b></td></tr>";
            }
            echo "<tr><td>&nbsp;</td></tr>";
            echo "</table>\n";
            $zberatel_s = "SELECT spolocnost.uid,user.meno,user.priezvisko,user.mail,user.tel FROM spolocnost,user WHERE spolocnost.id = '" . $about_user['spolid'] . "' AND user.id = spolocnost.uid";
            $zberatel_q = MySQL_Query($zberatel_s);
            $zberatel = MySQL_Fetch_Array($zberatel_q);
            $pic_s = "SELECT * FROM foto WHERE uid = '" . $zberatel['uid'] . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
            $pic_q = MySQL_Query($pic_s);
            $pic = MySQL_Fetch_Array($pic_q);
            echo "<table>\n";
            echo "<tr><td valign=\"top\" align=\"middle\"><img src=\"" . ((!Empty($pic['ftp'])) ? "foto/" . $pic['ftp'] : "images/no-photo.jpg" ) . "\" alt=\"\" /></td><td valign=\"top\" align=\"left\"><b>Kontaktná osoba v BMB Leitner CS</b><br /><br /><b>Meno:</b> " . $zberatel['meno'] . " " . $zberatel['priezvisko'] . "<br /><b>E-mail:</b> " . $zberatel['mail'] . "<br />" . ((!Empty($zberatel['tel'])) ? "<b>Telefón:</b> " . $zberatel['tel'] : "") . "</td><tr>\n";
            echo "</table>\n";
        }
    } else {
        //echo "<br /><b>V sekcii Dokumenty, si môžete stiahnuť výplatné pásky a pozrieť rôzne iné s vami súvisiace dukemty.</b><br />\n";
    }
}

function heslo() {
    $over_toto[] = "heslo_old,Súčasné heslo";
    $over_toto[] = "heslo_new1,Nové heslo";
    $over_toto[] = "heslo_new2,Nové heslo";

    check_js($over_toto);

    echo "<h2>" . preklad(78) . "</h2>\n";
    echo "<form action=\"\" method=\"post\" name=\"formular\" onsubmit=\"return check();\"><table>\n";
    echo "<tr><td><b>" . preklad(79) . "</b></td><td><input type=\"password\" name=\"heslo_old\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(80) . "</b></td><td><input type=\"password\" name=\"heslo_new1\" /></td></tr>\n";
    echo "<tr><td><b>" . preklad(80) . "</b></td><td><input type=\"password\" name=\"heslo_new2\" /></td></tr>\n";
    echo "<tr><td colspan=\"2\">" . preklad(81) . "</td></tr>\n";
    echo "<tr><td colspan=\"2\"><input type=\"hidden\" name=\"heslo_new\" value=\"1\"><input type=\"submit\" value=\"" . preklad(60) . "\" /></td></tr>\n";
    echo "</table></form>\n";
    if ($_GET['ch'] == 1)
        echo "<b>" . preklad(82) . "</b>";
    elseif ($_GET['ch'] == 2)
        echo "<b>" . preklad(83) . "</b>";
}

function heslo_sent() {
    global $user_id, $zedko;
    if ($zedko == 0)
        $old_s = "SELECT heslo FROM user WHERE id = '" . $user_id . "' ";
    else
        $old_s = "SELECT heslo FROM z WHERE id = '" . $user_id . "' ";
    $old_q = MySQL_Query($old_s);
    $old = MySQL_Fetch_Array($old_q);
    $pass_old_ok = MD5($_POST['heslo_old']);
    $pass_new1_ok = MD5($_POST['heslo_new1']);
    $pass_new2_ok = MD5($_POST['heslo_new2']);
    if ($pass_old_ok == $old['heslo']) {
        $dlzka_hesla = StrLen($_POST['heslo_new1']);
        if ($dlzka_hesla >= 8) {
            if (Eregi('^[a-z]+[0-9]', $_POST['heslo_new1']) || Eregi('^[0-9]+[a-z]', $_POST['heslo_new1'])) {
                if ($pass_new1_ok == $pass_new2_ok) {
                    if ($zedko == 0)
                        $zmen_u = "UPDATE user SET heslo = '" . $pass_new1_ok . "' WHERE id = '" . $user_id . "' ";
                    else
                        $zmen_u = "UPDATE z SET heslo = '" . $pass_new1_ok . "' WHERE id = '" . $user_id . "' ";
                    $zmen_q = MySQL_Query($zmen_u);
                    Header("Location: ?akc=9&ch=1");
                    exit();
                }
            }
        }
    }
    Header("Location: ?akc=9&ch=2");
    exit();
}

function spracovany_doc($co, $did) {
    $akt_dat = Date("Y-m-d");
    $spracuj_u = "UPDATE " . (($co == 1) ? "spol_docs" : "z_docs") . " SET datum_spracovania = '" . $akt_dat . "', spracovat = 0 WHERE id = '" . $did . "' ";
    $spracuj_q = MySQL_Query($spracuj_u);
    if ($_GET['spat'] == 11)
        Header("Location: ?akc=11");
    else
        Header("Location: ?");
    exit();
}

function bmb_vyber_spol() {
    global $user_id;
    echo "<br />\nspoločnosť: <select onChange=\"jx(this)\" size=\"1\"><option value=\"0\">- - - vyberte - - -</option>";
    $spols_s = "SELECT * FROM spolocnost WHERE uid = '" . $user_id . "' OR auid = '" . $user_id . "' ORDER BY nazov ASC";
    $spols_q = MySQL_Query($spols_s);
    while ($spols = MySQL_Fetch_Array($spols_q)) {
        echo "<option value=\"" . $spols['id'] . "\"" . (($spols['id'] == $_SESSION['bmb_spolid']) ? " selected" : "") . ">" . $spols['nazov'] . "</option>";
    }
    echo "</select>\n";
    echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lx = false;\nfunction jx(selObj){\n  if (lx) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lx = true;\n  eval(\"parent.location='home.php?bmb_zmen_spol=1&next=" . IntVal($_GET['akc']) . "&spolid=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
    echo "<br />";
}

function bmb_vyber_spol_zmen($spolid, $next) {
    $_SESSION['bmb_spolid'] = $spolid;
    Header("Location: ?akc=" . $next);
    exit();
}

function zoznam_zamestnancov_spol_x() {
    bmb_vyber_spol();

    echo "<h2>Zoznam zamestnancov</h2>\n";

    if (!Empty($_SESSION['bmb_spolid'])) {
        $spolid = $_SESSION['bmb_spolid'];

        $ord = Array("z.priezvisko", "stav.stav", "z.datum_prichodu", "z.datum_zmeny");
        $order = IntVal($_GET['order']);
        if (Empty($ord[$order])) {
            $order_ok = $ord[0];
            $order_x = 0;
        } else {
            $order_ok = $ord[$order];
            $order_x = $order;
        }

        $a = Array("ASC", "DESC");
        $a_obr = Array("asc", "desc");
        $asc = IntVal($_GET['asc']);
        if (Empty($a[$asc])) {
            $asc_ok = $a[0];
            $asc_x = 0;
        } else {
            $asc_ok = $a[$asc];
            $asc_x = $asc;
        }

        echo "<select onChange=\"jm(this)\" size=\"1\"><option value=\"0\"" . (($_SESSION['zobraz_zam'] == 0) ? " selected" : "") . ">všetci</option>";
        $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
        $stavy_q = MySQL_Query($stavy_s);
        while ($stavy = MySQL_Fetch_Array($stavy_q)) {
            echo "<option value=\"" . $stavy['id'] . "\"" . (($_SESSION['zobraz_zam'] == $stavy['id']) ? " selected" : "") . ">" . $stavy['stav'] . "</option>";
        }
        echo "</select><br />\n";
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?bmb_zmen_stav=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
        echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
        echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=10&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Meno:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=10&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Stav:</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=10&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Dátum nástupu:</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=10&order=3&asc=" . (($order_x == 3 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Posledná zmena:</a>" . (($order_x == 3) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>Počet dokumentov:</td><td>Výpis:</td></tr>\n";
        $akt_dat = Date("Y-m-d");
        $zam_s = "SELECT z.id,z.spolid,z.datum_pridania,z.datum_prichodu,z.datum_odchodu,z.meno,z.priezvisko,z.datum_zmeny,z.stavid,z.active,stav.stav FROM z,stav WHERE spolid = '" . $spolid . "' AND stav.id = z.stavid ";
        if ($_SESSION['zobraz_zam'] > 0)
            $zam_s .= "AND stavid = '" . $_SESSION['zobraz_zam'] . "' ";
        else
            $zam_s .= "";
        $zam_s .= "ORDER BY " . $order_ok . " " . $asc_ok;
        $zam_q = MySQL_Query($zam_s);
        $i = 1;
        while ($zam = MySQL_Fetch_Array($zam_q)) {
            echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td>" . $zam['priezvisko'] . " " . $zam['meno'] . "</td><td>" . $zam['stav'] . "</td><td>" . date_conv_to_view($zam['datum_prichodu']) . "</td><td>" . date_conv_to_view($zam['datum_zmeny']) . "</td><td align=\"center\">" . z_pocet_dok($zam['id']) . "</td><td><a href=\"home.php?akc=10&akc2=2&zid=" . $zam['id'] . "\">aktuálny</a> <a href=\"home.php?akc=10&akc2=3&zid=" . $zam['id'] . "\">úplný</a></td></tr>\n";
            $i++;
        }
        echo "</table>";
    }
}

function bmb_zobraz_zam($zobraz, $vp) {
    if ($zobraz == 0 || $zobraz == 1 || $zobraz == 2 || $zobraz == 3) {
        $_SESSION['zobraz_zam'] = $zobraz;
    }
    if ($vp == 1)
        Header("Location: ?akc=15");
    else
        Header("Location: ?akc=10");
}

function pristup_zid_x($zid) {
    global $user_id;

    $over2_s = "SELECT spolid FROM z WHERE id = '" . $zid . "' ";
    $over2_q = MySQL_Query($over2_s);
    $over2 = MySQL_Fetch_Array($over2_q);

    $over1_s = "SELECT uid,auid FROM spolocnost WHERE id = '" . $over2['spolid'] . "' ";
    $over1_q = MySQL_Query($over1_s);
    $over1 = MySQL_Fetch_Array($over1_q);

    if (($over1['uid'] == $user_id) || ($over1['auid'] == $user_id))
        $ret = 1;
    else
        $ret = 0;

    return $ret;
}

function zoznam_docs_zam_x($zid) {
    $docs_s = "SELECT * FROM z_docs WHERE zid = '" . $zid . "' ORDER BY nazov ASC";
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    if ($docs_n > 0) {
        $i = 1;
        $ret = "<table>";
        $ret .= "<tr><td>#</td><td>Názov dokumentu:</td><td>Dátum pridania:</td></tr>";
        while ($docs = MySQL_Fetch_Array($docs_q)) {
            $ret .= "<tr><td>" . $i . "</td><td><a href=\"get_file.php?did=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td></tr>";
            $i++;
        }
        $ret .= "</table>";
    } else {
        $ret = "K tomuto zamestnancovi neboli pridané žiadne dokumenty.";
    }
    return $ret;
}

function profil_zamestnanec_spol_x($zid) {
    echo "<h2>Aktuálny výpis zamestnanca</h2>\n";
    $povol = pristup_zid_x("$zid");
    if ($povol == 1) {
        echo "<table width=\"100%\">\n";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">Osobné údaje</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_meno WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Meno:</td><td class=\"vypis_tab_main\">" . $nac['meno'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Priezvisko:</td><td class=\"vypis_tab_main\">" . $nac['priezvisko'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_titul WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['titul']))
            echo "<tr><td class=\"vypis_tab_left\">Titul:</td><td class=\"vypis_tab_main\">" . $nac['titul'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko_rodne WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Rodné priezvisko:</td><td class=\"vypis_tab_main\">" . $nac['priezvisko_rodne'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodne_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Rodné číslo:</td><td class=\"vypis_tab_main\">" . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nar = date_conv_to_view($nac['datum_narodenia']);
        echo "<tr><td class=\"vypis_tab_left\">Dátum narodenia:</td><td class=\"vypis_tab_main\">" . $dat_nar . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_miesto_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Miesto narodenia:</td><td class=\"vypis_tab_main\">" . $nac['miesto'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_tel_cislo WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['tel']))
            echo "<tr><td class=\"vypis_tab_left\">Tel. číslo:</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_narodnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Národnosť:</td><td class=\"vypis_tab_main\">" . $nac['narodnost'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_statna_prislusnost WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Štátna príslušnosť:</td><td class=\"vypis_tab_main\">" . $nac['prislusnost'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_obciansky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['obciansky']))
            echo "<tr><td class=\"vypis_tab_left\">Číslo občianskeho preukazu:</td><td class=\"vypis_tab_main\">" . $nac['obciansky'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_vodicsky_preukaz WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['vodicsky']))
            echo "<tr><td class=\"vypis_tab_left\">Vodičský preukaz:</td><td class=\"vypis_tab_main\">" . $nac['vodicsky'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodinny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Rodinný stav:</td><td class=\"vypis_tab_main\">" . $nac['stav'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotny_stav WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['stav']))
            echo "<tr><td class=\"vypis_tab_left\">Zdravotný stav:</td><td class=\"vypis_tab_main\">" . $nac['stav'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT z_zdravotna_poistovna.pid,poistovna.nazov,DATE_FORMAT(z_zdravotna_poistovna.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotna_poistovna,poistovna WHERE z_zdravotna_poistovna.zid = '" . $zid . "' AND poistovna.id = z_zdravotna_poistovna.pid ORDER BY z_zdravotna_poistovna.id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Zdravotná poisťovňa:</td><td class=\"vypis_tab_main\">" . $nac['nazov'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_trvale WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Trvalé bydlisko</td><td> od:" . $nac['dat_od'] . "</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">Adresa:</td><td class=\"vypis_tab_main\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td>&nbsp;</td></tr>";
        if (!Empty($nac['tel']))
            echo "<tr><td class=\"vypis_tab_left\">Tel. číslo:</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";



        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_prechodne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['ulica'])) {
            echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
            echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Prechodné bydlisko</td><td> od:" . $nac['dat_od'] . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">Adresa:</td><td class=\"vypis_tab_main\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td>&nbsp;</td></tr>";
            if (!Empty($nac['tel']))
                echo "<tr><td class=\"vypis_tab_left\">Tel. číslo:</td><td class=\"vypis_tab_main\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";
        }


        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(z_cislo_uctu.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_cislo_uctu,banka WHERE z_cislo_uctu.zid = '" . $zid . "' AND banka.kod = z_cislo_uctu.cislo2 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Účet v banke, na ktorý sa bude posielať mzda</td><td> od:" . $nac['dat_od'] . "</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">Názov banky:</td><td class=\"vypis_tab_main\">" . $nac['nazov'] . "</td><td>&nbsp;</td></tr>";
        echo "<tr><td class=\"vypis_tab_left\">Číslo účtu:</td><td class=\"vypis_tab_main\">" . (($nac['cislo0'] > 0) ? $nac['cislo0'] . "-" : "") . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td>&nbsp;</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Iné údaje</td></tr>";

        $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nastup = date_conv_to_view($nac['datum_prichodu']);
        echo "<tr><td class=\"vypis_tab_left\">Dátum nástupu do zamestnania:</td><td class=\"vypis_tab_main\">" . $dat_nastup . "</td><td>&nbsp;</td></tr>";
        $dat_odchod = date_conv_to_view($nac['datum_odchodu']);
        if ($dat_odchod > "00.00.0000")
            echo "<tr><td class=\"vypis_tab_left\">Dátum skončenia pracovného pomeru:</td><td class=\"vypis_tab_main\">" . $dat_odchod . "</td><td>&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_druh_pomeru WHERE zid = '" . $zid . "' ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Druh pracovného pomeru:</td><td class=\"vypis_tab_main\">" . $nac['druh'] . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_ukonc_posled_zam WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_ukonc = date_conv_to_view($nac['datum_ukoncenia']);
        if (!Empty($nac['datum_ukoncenia']))
            echo "<tr><td class=\"vypis_tab_left\">Dátum ukončenia posledného zamestnania:</td><td class=\"vypis_tab_main\">" . $dat_ukonc . "</td><td> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_ostatne WHERE zid = '" . $zid . "' AND active = 1 ORDER BY id DESC LIMIT 0,1";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        if (!Empty($nac['ostatne']))
            echo "<tr><td class=\"vypis_tab_left\">Ostatné údaje:</td><td>" . $nac['ostatne'] . "</td><td class=\"vypis_tab_main\"> od:" . $nac['dat_od'] . "</td></tr>";

        $nac_s = "SELECT stav.stav FROM z,stav WHERE z.id = '" . $zid . "' AND stav.id = z.stavid ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Stav:</td><td>" . $nac['stav'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        $nac_s = "SELECT fond FROM z WHERE z.id = '" . $zid . "'";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Fond:</td><td>" . $nac['fond'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        $nac_s = "SELECT costCenter FROM z WHERE z.id = '" . $zid . "'";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Cost Center:</td><td>" . $nac['costCenter'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Dokumenty</td></tr>";

        echo "<tr><td colspan=\"2\">" . zoznam_docs_zam_x($zid) . "</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" style=\"font-weight: bold;\"><a href=\"?akc=10&akc2=3&zid=" . $zid . "\">zobraziť úplný výpis</a></td></tr>";

        echo "</table>\n";
    }
    else {
        echo "takýto zamestnanec neexistuje!";
    }
}

function profil_zamestnanec_spol2_x($zid) {
    echo "<h2>Úplný výpis zamestnanca</h2>\n";
    $povol = pristup_zid_x("$zid");
    if ($povol == 1) {
        echo "<table width=\"100%\">\n";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">Osobné údaje</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_meno WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Meno:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['meno'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Priezvisko:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['priezvisko'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_titul WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Titul:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['titul'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_priezvisko_rodne WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Rodné priezvisko:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['priezvisko_rodne'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodne_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Rodné číslo:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            $dat_nar = date_conv_to_view($nac['datum_narodenia']);
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Dátum narodenia:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $dat_nar . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_miesto_narodenia WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Miesto narodenia:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['miesto'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_tel_cislo WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Tel. číslo:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['tel'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_narodnost WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Národnosť:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['narodnost'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_statna_prislusnost WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Štátna príslušnosť:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['prislusnost'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_obciansky_preukaz WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Číslo občianskeho preukazu:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['obciansky'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_vodicsky_preukaz WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Vodičský preukaz:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['vodicsky'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_rodinny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Rodinný stav:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['stav'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotny_stav WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Zdravotný stav:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['stav'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT z_zdravotna_poistovna.pid,poistovna.nazov,DATE_FORMAT(z_zdravotna_poistovna.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_zdravotna_poistovna,poistovna WHERE z_zdravotna_poistovna.zid = '" . $zid . "' AND poistovna.id = z_zdravotna_poistovna.pid ORDER BY z_zdravotna_poistovna.id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Zdravotná poisťovňa:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['nazov'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_trvale WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            if ($i == 1)
                echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Trvalé bydlisko</td><td>&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Adresa:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            if (!Empty($nac['tel']))
                echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Tel. číslo:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";
            $i++;
        }


        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_bydlisko_prechodne WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            if ($i == 1) {
                echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
                echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Prechodné bydlisko</td><td>&nbsp;</td></tr>";
            }
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Adresa:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['ulica'] . ", " . $nac['psc'] . " " . $nac['mesto'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            if (!Empty($nac['tel']))
                echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Tel. číslo:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['tel'] . "</td><td>&nbsp;</td></tr>";
            $i++;
        }


        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(z_cislo_uctu.datum_pridania, '%d.%m.%Y') AS dat_od FROM z_cislo_uctu,banka WHERE z_cislo_uctu.zid = '" . $zid . "' AND banka.kod = z_cislo_uctu.cislo2 ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            if ($i == 1)
                echo "<tr><td colspan=\"2\" class=\"vypis_tab_celok\">Účet v banke, na ktorý sa bude posielať mzda</td><td>&nbsp;</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Názov banky:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['nazov'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Číslo účtu:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . (($nac['cislo0'] > 0) ? $nac['cislo0'] . "-" : "") . $nac['cislo1'] . "/" . $nac['cislo2'] . "</td><td>&nbsp;</td></tr>";
            $i++;
        }

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">Iné údaje</td></tr>";

        $nac_s = "SELECT * FROM z WHERE id = '" . $zid . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        $dat_nastup = date_conv_to_view($nac['datum_prichodu']);
        echo "<tr><td class=\"vypis_tab_left\">Dátum nástupu do zamestnania:</td><td class=\"vypis_tab_main\">" . $dat_nastup . "</td><td>&nbsp;</td></tr>";
        $dat_odchod = date_conv_to_view($nac['datum_odchodu']);
        if ($dat_odchod > "00.00.0000")
            echo "<tr><td class=\"vypis_tab_left\">Dátum skončenia pracovného pomeru:</td><td class=\"vypis_tab_main\">" . $dat_odchod . "</td><td>&nbsp;</td></tr>";

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_druh_pomeru WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Druh pracovného pomeru:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1) ? " gray" : "") . "\">" . $nac['druh'] . "</td><td class=\"vypis_tab_right" . (($i > 1) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_datum_ukonc_posled_zam WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            $dat_ukonc = date_conv_to_view($nac['datum_ukoncenia']);
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Dátum ukončenia posledného zamestnania:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $dat_ukonc . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT *,DATE_FORMAT(datum_pridania, '%d.%m.%Y') AS dat_od FROM z_ostatne WHERE zid = '" . $zid . "' ORDER BY id DESC";
        $nac_q = MySQL_Query($nac_s);
        $i = 1;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            echo "<tr><td class=\"vypis_tab_left\">" . (($i == 1) ? "Ostatné údaje:" : "&nbsp;") . "</td><td class=\"vypis_tab_main" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\">" . $nac['ostatne'] . "</td><td class=\"vypis_tab_right" . (($i > 1 || $nac['active'] == 0) ? " gray" : "") . "\"> od:" . $nac['dat_od'] . "</td></tr>";
            $i++;
        }

        $nac_s = "SELECT stav.stav FROM z,stav WHERE z.id = '" . $zid . "' AND stav.id = z.stavid ";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Stav:</td><td>" . $nac['stav'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        $nac_s = "SELECT fond FROM z WHERE z.id = '" . $zid . "'";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Fond:</td><td>" . $nac['fond'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        $nac_s = "SELECT costCenter FROM z WHERE z.id = '" . $zid . "'";
        $nac_q = MySQL_Query($nac_s);
        $nac = MySQL_Fetch_Array($nac_q);
        echo "<tr><td class=\"vypis_tab_left\">Cost Center:</td><td>" . $nac['costCenter'] . "</td><td class=\"vypis_tab_main\">&nbsp;</td></tr>";

        echo "<tr><td colspan=\"3\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"3\" class=\"vypis_tab_celok\">Dokumenty</td></tr>";

        echo "<tr><td colspan=\"3\">" . zoznam_docs_zam_x($zid) . "</td></tr>";

        echo "<tr><td colspan=\"2\">&nbsp;</td></tr>";
        echo "<tr><td colspan=\"2\" style=\"font-weight: bold;\"><a href=\"?akc=10&akc2=2&zid=" . $zid . "\">zobraziť aktuálny výpis</a></td></tr>";

        echo "</table>\n";
    } else {
        echo "takýto zamestnanec neexistuje!";
    }
}

function zoznam_docs_firma_x() {
    $ord = Array("nazov", "datum_pridania", "datum_spracovania");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }
    $spolid = $_SESSION['bmb_spolid'];
    $docs_s = "SELECT * FROM spol_docs WHERE spolid = '" . $spolid . "' ORDER BY " . $order_ok . " " . $asc_ok;
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    $i = 1;
    $ret = "<table>";
    $ret .= "<tr><td>#</td><td><a href=\"?akc=11&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">Názov dokumentu:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=11&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">Dátum pridania:</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=11&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">Dátum spracovania:</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td></tr>";
    while ($docs = MySQL_Fetch_Array($docs_q)) {
        $ret .= "<tr><td>" . $i . "</td><td><a href=\"get_file_spol.php?did=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td><td>" . (($docs['spracovat'] == 1) ? "<a href=\"?spracovane=1&co=1&did=" . $docs['id'] . "&spat=11\">označiť ako spracované</a>" : date_conv_to_view($docs['datum_spracovania'])) . "</td></tr>";
        $i++;
    }
    $ret .= "</table>";
    return $ret;
}

function dokument_user_x() {
    bmb_vyber_spol();

    echo "<h2>Dokumenty</h2>\n";

    if (!Empty($_SESSION['bmb_spolid'])) {
        $nac2_s = "SELECT nazov FROM spolocnost WHERE id = '" . $_SESSION['bmb_spolid'] . "' ";
        $nac2_q = MySQL_Query($nac2_s);
        $nac2 = MySQL_Fetch_Array($nac2_q);
        $nazov_firmy = $nac2['nazov'];
        echo "<b>Dokumenty odovzdané za " . $nazov_firmy . ":</b>\n";
        echo "<br / >";
        echo zoznam_docs_firma_x();
    }
}

function dochadzka_x() {
    bmb_vyber_spol();
    //echo $_SESSION['bmb_spolid'];
    echo "<h2>Dochádzka</h2>\n";
    if (!Empty($_SESSION['bmb_spolid'])) {
        global $user_id;

        $spol_s = "SELECT falkensteinerMode FROM spolocnost WHERE id='" . $_SESSION['bmb_spolid'] . "'";
        $spol_q = MySQL_Query($spol_s);
        $spol = MySQL_Fetch_Array($spol_q);
        if ($spol['falkensteinerMode'] == 1) {
            $bodNula = ZERO;
            include('vystupna_dochadzka.php');
        } else {

            $nac_s = "SELECT dtid,pracovny_vikend,pracovny_sviatok,zac_mesiac,zac_rok FROM spolocnost WHERE id = '" . $_SESSION['bmb_spolid'] . "' ";
            $nac_q = MySQL_Query($nac_s);
            $nac = MySQL_Fetch_Array($nac_q);
            $spolid = $_SESSION['bmb_spolid'];
            $prvy_y = $nac['zac_rok'];
            $prvy_m = $nac['zac_mesiac'];
            $now_y = Date("Y");
            $now_m = Date("n");
//$now_m = 10;
            $now_d = Date("j");
//$now_d = 1;

            if ((($prvy_m > $now_m) && ($prvy_y == $now_y)) || ($prvy_y > $now_y)) {
                echo "Spoločnosť ešte nezačala odovzdávať dochádzku.";
            } else {
                if ($now_m == 12) {
                    $nasl_m = 1;
                    $nasl_y = $now_y + 1;
                } else {
                    $nasl_m = $now_m + 1;
                    $nasl_y = $now_y;
                }

                $posl_y = $now_y;
                $posl_m = $now_m;

                if (Empty($_SESSION['doch_rok']))
                    $_SESSION['doch_rok'] = $posl_y;
                if (Empty($_SESSION['doch_mes']))
                    $_SESSION['doch_mes'] = $posl_m;

                if ($_SESSION['doch_rok'] < $prvy_y || $_SESSION['doch_rok'] > $posl_y) {
                    $_SESSION['doch_rok'] = $posl_y;
                }
                if ($_SESSION['doch_rok'] == $prvy_y && $_SESSION['doch_mes'] < $prvy_m) {
                    $_SESSION['doch_rok'] = $posl_y;
                    $_SESSION['doch_mes'] = $posl_m;
                }
                if ($_SESSION['doch_rok'] == $posl_y && $_SESSION['doch_mes'] > $posl_m) {
                    $_SESSION['doch_rok'] = $posl_y;
                    $_SESSION['doch_mes'] = $posl_m;
                }

                echo "<table><tr><td>zobraziť:&nbsp;<select onChange=\"jm(this)\" size=\"1\">";
                for ($i = $now_y; $i >= $prvy_y; $i--) {
                    if ($i == $prvy_y)
                        $od = $prvy_m;
                    else
                        $od = 1;
                    if ($i == $now_y)
                        $to = $now_m;
                    else
                        $to = 12;
                    for ($j = $to; $j >= $od; $j--) {
                        $ov_s = "SELECT id FROM uzamknutie WHERE spolid = '" . $spolid . "' AND mesiac = '" . $j . "' AND rok = '" . $i . "' ";
                        $ov_q = MySQL_Query($ov_s);
                        $ov_n = MySQL_Num_Rows($ov_q);
                        echo "<option value=\"" . $j . "," . $i . "\"" . (($i == $_SESSION['doch_rok'] && $j == $_SESSION['doch_mes']) ? " selected" : "") . ">" . mesiac_sk($j) . " " . $i . (($ov_n > 0) ? "" : " *") . "</option>";
                    }
                }
                echo "</select>\n</td><td>";
                $over_s = "SELECT id,typid FROM uzamknutie WHERE spolid = '" . $spolid . "' AND mesiac = '" . $_SESSION['doch_mes'] . "' AND rok = '" . $_SESSION['doch_rok'] . "' ";
                $over_q = MySQL_Query($over_s);
                $over_n = MySQL_Num_Rows($over_q);
                if ($over_n == 0) {
                    echo "&nbsp;";
                } else {
                    $over = MySQL_Fetch_Array($over_q);
                    echo "<a href=\"export_excel.php?spolid=" . $spolid . "&mesiac=" . $_SESSION['doch_mes'] . "&rok=" . $_SESSION['doch_rok'] . "\">export</a>";
                }
                echo "</td></tr></table>\n";
                echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?zmen_doch_x=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
                echo "<br />";
                if ($over_n > 0) {
                    echo "<form action=\"\" method=\"post\" name=\"formular\" enctype=\"multipart/form-data\">\n";
                    echo "<b><u>Výsledky spracovania miezd:</u></b>";
                    echo form_viac_suborov(10);
                    echo "<input type=\"hidden\" name=\"uloz_14_doc\" value=\"1\" /><input type=\"submit\" value=\"Uložiť\" />";
                    echo "</form>";
                }
                docs_14_x($spolid);
                echo "<br /><br />";

                if ($over_n == 0) {
                    if ($nac['dtid'] == 1)
                        dochadzka_kalendar_x($spolid, $over_n);
                    else
                        dochadzka_zoznam_x($spolid, $over_n);
                }
                else {
                    if ($over['typid'] == 1)
                        dochadzka_kalendar_x($spolid, $over_n);
                    else
                        dochadzka_zoznam_x($spolid, $over_n);
                }
            }
        }
    }
}

function doc_14_sent() {
    $spolid = $_SESSION['bmb_spolid'];

    if (!Empty($_FILES['subor']['name'])) {
        $i = 1;
        while (list($key, $value) = each($_FILES['subor']['name'])) {
            if (!Empty($value)) {
                $filename = Trim(HtmlSpecialChars($value));
                $filename = Str_Replace(" ", "_", $filename);
                $ftp = "document_mzdy_" . $spolid . "_" . MD5(MicroTime()) . "_" . $i;
                $document = $_FILES['subor']['tmp_name'][$key];
                $type = ($_FILES['subor']['type'][$key]);
                @mkdir($document, 0777);
                @chmod($document, 0777);
                if (Move_Uploaded_File($document, DOCS_ADDRESS . $ftp)) {
                    $akt_dat = Date("Y-m-d");
                    $uloz_i = "INSERT INTO mzdy_docs (id, nazov, ftp, type, datum_pridania, spolid, mesiac, rok, active) VALUES (NULL, '" . $filename . "', '" . $ftp . "', '" . $type . "', '" . $akt_dat . "', '" . $spolid . "', '" . $_SESSION['doch_mes'] . "', '" . $_SESSION['doch_rok'] . "', 1)";
                    $uloz_q = MySQL_Query($uloz_i);
                }
                $i++;
            }
        }
        if ($i > 1) {
            $starost_s = "SELECT spolocnost.nazov,spolocnost.uid,user.mail FROM spolocnost,user WHERE spolocnost.id = '" . $spolid . "' AND user.id = spolocnost.uid ";
            $starost_q = MySQL_Query($starost_s);
            $starost = MySQL_Fetch_Array($starost_q);
            $komu = $starost['mail'];

            $prisp_s = "SELECT id,mail FROM user WHERE spolid = '" . $spolid . "' AND admin = 1 AND notifikacia = 1";
            $prisp_q = MySQL_Query($prisp_s);
            while ($prisp = MySQL_Fetch_Array($prisp_q)) {
                $komu .= ", " . $prisp['mail'];
            }

            $predmet = "mzdy.bmbleitner.sk";
            $text = "Spoločnosť " . $starost['nazov'] . ":<br />\n";
            $text .= "K mesiacu " . mesiac_sk($_SESSION['doch_mes']) . " " . $_SESSION['doch_rok'] . " boli pridané Výsledky spracovania miezd.";

            poslat_email($komu, $predmet, $text);
        }
    }
}

function docs_14_x($spolid) {
    $subory_s = "SELECT * FROM mzdy_docs WHERE spolid = '" . $spolid . "' AND mesiac = '" . $_SESSION['doch_mes'] . "' AND rok = '" . $_SESSION['doch_rok'] . "' ORDER BY nazov ASC";
    $subory_q = MySQL_Query($subory_s);
    $subory_n = MySQL_Num_Rows($subory_q);
    if ($subory_n > 0) {
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nfunction odstranit(nazov)\n{\nreturn confirm(\"Naozaj chcete odstrániť vzorový dokument \" + nazov + \"?\");\n}\n//-->\n</script>\n";
        echo "<table>\n";
        echo "<tr><td>#</td><td>Názov:</td><td>Dátum pridania:</td><td>&nbsp;</td></tr>\n";
        $i = 1;
        while ($subory = MySQL_Fetch_Array($subory_q)) {
            echo "<tr><td>" . $i . "</td><td><a href=\"get_file_mzdy.php?did=" . $subory['id'] . "\">" . $subory['nazov'] . "</a></td><td>" . date_conv_to_view($subory['datum_pridania']) . "</td><td><a href=\"?del_subor_mzda=1&did=" . $subory['id'] . "\" onclick=\"return odstranit('" . $subory['nazov'] . "');\">vymazať</a></td></tr>\n";
            $i++;
        }
        echo "</table>\n";
    }
}

function del_subor_mzda_x($did) {
    global $user_id;
    $ov1_s = "SELECT spolid FROM mzdy_docs WHERE id = '" . $did . "' ";
    $ov1_q = MySQL_Query($ov1_s);
    $ov1 = MySQL_Fetch_Array($ov1_q);
    $ov2_s = "SELECT uid FROM spolocnost WHERE id = '" . $ov1['spolid'] . "' ";
    $ov2_q = MySQL_Query($ov2_s);
    $ov2 = MySQL_Fetch_Array($ov2_q);
    if ($ov2['uid'] == $user_id) {
        $zmaz_d = "DELETE FROM mzdy_docs WHERE id = '" . $did . "' ";
        $zmaz_q = MySQL_Query($zmaz_d);
    }
    Header("Location: ?akc=12");
    exit();
}

function zmen_doch_x($mes, $rok) {
    $_SESSION['doch_rok'] = $rok;
    $_SESSION['doch_mes'] = $mes;
    Header("Location: ?akc=12");
    exit();
}

function dochadzka_kalendar_x($spolid, $over_n) {
//global $user_id;
    $mesiac = $_SESSION['doch_mes'];
    $rok = $_SESSION['doch_rok'];
    $mesiac_time = mktime(0, 0, 0, $mesiac, 1, $rok);
    $pocet_dni = Date("t", $mesiac_time);

    $sviat_s = "SELECT * FROM sviatok WHERE mesiac = '" . $mesiac . "' AND rok = '" . $rok . "' ORDER BY den ASC";
    $sviat_q = MySQL_Query($sviat_s);
    $sv = Array();
    while ($sviat = MySQL_Fetch_Array($sviat_q)) {
        $sv[] = $sviat['den'];
    }

    echo "<table cellpadding=\"1\" cellspacing=\"1\" class=\"tabulka_doch\">\n";
    echo "<tr class=\"nadpis\">";
    echo "<td>#</td><td align=\"left\">Meno:</td>";
    for ($i = 1; $i <= $pocet_dni; $i++) {
        $den_time = mktime(0, 0, 0, $mesiac, $i, $rok);
        $den_typ = Date("w", $den_time);
        if ($den_typ == 0)
            $den_typ = 7;
        echo "<td align=\"center\">$i</td>";
    }
    echo "<td align=\"left\">Meno:</td></tr>\n";
    echo "<tr>";
    echo "<td>&nbsp;</td><td align=\"left\">&nbsp;</td>";
    for ($i = 1; $i <= $pocet_dni; $i++) {
        $den_time = mktime(0, 0, 0, $mesiac, $i, $rok);
        $den_typ = Date("w", $den_time);
        if ($den_typ == 0)
            $den_typ = 7;

        if (In_Array($i, $sv)) {
            echo "<td align=\"center\" class=\"vikend\">sv.</td>";
        } else {
            if ($den_typ == 6)
                echo "<td align=\"center\" class=\"vikend\">So</td>";
            elseif ($den_typ == 7)
                echo "<td align=\"center\" class=\"vikend\">Ne</td>";
            else
                echo "<td align=\"center\">&nbsp;</td>";
        }
    }
    echo "<td align=\"left\">&nbsp;</td></tr>\n";

    $spol_s = "SELECT * FROM spolocnost WHERE id = '" . $spolid . "' ";
    $spol_q = MySQL_Query($spol_s);
    $spol = MySQL_Fetch_Array($spol_q);
    $prac_vikend = $spol['pracovny_vikend'];
    $prac_sviatok = $spol['pracovny_sviatok'];
    $akt_dat = Date("Y-m-d");
    if ($over_n == 0)
        $zam_s = "SELECT * FROM z WHERE spolid = '" . $spolid . "' AND stavid = 1 ORDER BY priezvisko ASC";
    else
        $zam_s = "SELECT z.id,z.meno,z.priezvisko FROM dochadzka_historia,z WHERE dochadzka_historia.spolid = '" . $spolid . "' AND dochadzka_historia.rok = '" . $rok . "' AND dochadzka_historia.mesiac = '" . $mesiac . "' AND z.id = dochadzka_historia.zid ORDER BY z.priezvisko ASC";
    $zam_q = MySQL_Query($zam_s);
    $j = 1;
    while ($zam = MySQL_Fetch_Array($zam_q)) {
        echo "<tr class=\"zamestnanec\">";
        echo "<td>" . $j . "</td><td align=\"left\"><a href=\"?akc=10&akc2=2&zid=" . $zam['id'] . "\" class=\"a_kal_meno\">" . $zam['priezvisko'] . "&nbsp;" . $zam['meno'] . "</a></td>";
        for ($i = 1; $i <= $pocet_dni; $i++) {
            $den_time = mktime(0, 0, 0, $mesiac, $i, $rok);
            $den_typ = Date("w", $den_time);
            if ($den_typ == 0)
                $den_typ = 7;
            if (In_Array($i, $sv))
                $s = 1;
            else
                $s = 0;
            echo "<td align=\"center\" class=\"" . (($den_typ >= 6 || In_Array($i, $sv)) ? "vikend" : "den") . "\">" . (($over_n == 0) ? dochadzka_sel($den_typ, $zam['id'], $i, $mesiac, $rok, $prac_vikend, $s, $prac_sviatok) : dochadzka_sel_uzamk($zam['id'], $i, $mesiac, $rok) ) . "</td>";
        }
        echo "<td align=\"left\"><a href=\"?akc=10&akc2=2&zid=" . $zam['id'] . "\" class=\"a_kal_meno\">" . $zam['priezvisko'] . "&nbsp;" . $zam['meno'] . "</a></td></tr>\n";
        $j++;
    }

    echo "</table>\n";
    echo "<table>\n";
    $pozn_s = "SELECT text FROM dochadzka_text WHERE spolid = '" . $spolid . "' AND mesiac = '" . $mesiac . "' AND rok = '" . $rok . "' ORDER BY id DESC LIMIT 0,1";
    $pozn_q = MySQL_Query($pozn_s);
    $pozn = MySQL_Fetch_Array($pozn_q);
    echo "<tr><td valign=\"top\">Poznámka:</td><td valign=\"top\" style=\"width: 350px;\"><b>" . zalamovanie_na_vypis($pozn['text']) . "</b></td><td valign=\"top\">";
    $stlpcov = 2;
    $typy_s = "SELECT * FROM praca WHERE skratka != '' AND tyzden < 3 ORDER BY skratka ASC";
    $typy_q = MySQL_Query($typy_s);
    $typy_n = MySQL_Num_Rows($typy_q);
    $poc = Ceil($typy_n / $stlpcov);
    $i = 1;
    while ($typy = MySQL_Fetch_Array($typy_q)) {
        echo "<font style=\"background-color: #" . $typy['farba'] . ";\">&nbsp;" . $typy['skratka'] . " - " . $typy['nazov'] . "&nbsp;</font><br />\n";
        if ($i % $poc == 0 && $i != $typy_n)
            echo "</td><td valign=\"top\">";
        $i++;
    }
    echo "</td><tr>";
    echo "</table>\n";
}

function dochadzka_zoznam_x($spolid, $over_n) {
//global $user_id;
    $mesiac = $_SESSION['doch_mes'];
    $rok = $_SESSION['doch_rok'];
    $mesiac_time = mktime(0, 0, 0, $mesiac, 1, $rok);
    $pocet_dni = Date("t", $mesiac_time);
    echo "<table>\n";
    $pozn_s = "SELECT text FROM dochadzka_text WHERE spolid = '" . $spolid . "' AND mesiac = '" . $mesiac . "' AND rok = '" . $rok . "' ORDER BY id DESC LIMIT 0,1";
    $pozn_q = MySQL_Query($pozn_s);
    $pozn = MySQL_Fetch_Array($pozn_q);
    echo "<tr><td valign=\"top\">Poznámka:</td><td valign=\"top\" style=\"width: 350px;\"><b>" . zalamovanie_na_vypis($pozn['text']) . "</b></td><td valign=\"top\">";
    $stlpcov = 2;
    $typy_s = "SELECT * FROM praca WHERE skratka != '' AND id != 1 ORDER BY skratka ASC";
    $typy_q = MySQL_Query($typy_s);
    $typy_n = MySQL_Num_Rows($typy_q);
    $poc = Ceil($typy_n / $stlpcov);
    $i = 1;
    while ($typy = MySQL_Fetch_Array($typy_q)) {
        echo "<font style=\"background-color: #" . $typy['farba'] . ";\">&nbsp;" . $typy['skratka'] . " - " . $typy['nazov'] . "&nbsp;</font><br />\n";
        if ($i % $poc == 0 && $i != $typy_n)
            echo "</td><td valign=\"top\">";
        $i++;
    }
    echo "</td><tr>";
    echo "</table>\n";
    echo "<br /><br />\n";

    $ord = Array("z.priezvisko", "dochadzka_nepritomnost.den_od", "dochadzka_nepritomnost.den_do", "praca.skratka");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }

    echo "<u>Pridané neprítomnosti:</u><br />\n";
    echo "<table>\n";
    echo "<tr><td>#</td><td><a href=\"?akc=12&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">Meno:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=12&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">od:</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=12&order=2&asc=" . (($order_x == 2 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">do:</a>" . (($order_x == 2) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=12&order=3&asc=" . (($order_x == 3 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">Dôvod:</a>" . (($order_x == 3) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td></tr>\n";
    $neprit_s = "SELECT dochadzka_nepritomnost.id,dochadzka_nepritomnost.den_od,dochadzka_nepritomnost.den_do,dochadzka_nepritomnost.pid,dochadzka_nepritomnost.text,z.meno,z.priezvisko,praca.skratka,praca.farba FROM dochadzka_nepritomnost,z,praca WHERE dochadzka_nepritomnost.spolid = '" . $spolid . "' AND dochadzka_nepritomnost.rok = '" . $rok . "' AND dochadzka_nepritomnost.mesiac = '" . $mesiac . "' AND z.id = dochadzka_nepritomnost.zid AND praca.id = dochadzka_nepritomnost.pid ORDER BY " . $order_ok . " " . $asc_ok;
    $neprit_q = MySQL_Query($neprit_s);
    $i = 1;
    while ($neprit = MySQL_Fetch_Array($neprit_q)) {
        echo "<tr><td>" . $i . "</td><td>" . $neprit['priezvisko'] . " " . $neprit['meno'] . " &nbsp;</td><td><b>" . $neprit['den_od'] . "</b>." . $mesiac . "." . $rok . "</td><td><b>" . $neprit['den_do'] . "</b>." . $mesiac . "." . $rok . "</td><td><font style=\"background-color: #" . $neprit['farba'] . ";\">&nbsp;" . $neprit['skratka'] . "&nbsp;</font>" . (($neprit['pid'] == 15) ? " - " . $neprit['text'] : "") . "</td></tr>\n";
        $i++;
    }
    echo "</table>\n";
}

function poslat_email($komu, $predmet, $text, $show_error = false) {

    $sprava = $text;

    $sprava .= "\n<br /><br />\n----------------------------------------\n<br />";
    $sprava .= "správa bola automaticky vygenerovaná a odoslaná z <a href=\"https://payroll.bmbleitner.sk/falkensteiner\">https://payroll.bmbleitner.sk/falkensteiner</a>\n<br />";
    $sprava .= "na túto správu prosíme neodpovedať";

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->Host = "mail.alfacentauri.sk";

    $mail->SMTPAuth = true;
    $mail->Mailer = "smtp";
    $mail->Password = "KaP386Any";
    $mail->Username = "noreply";
    $mail->SMTPSecure = 'tls';

    $mail->From = "noreply@bmbleitner.sk";
    $mail->FromName = "mzdy.bmbleitner.sk";
    $mail->AddAddress($komu, $komu);
    $mail->AddReplyTo("sec@alfac.sk", "Andrej Seč");
    $mail->WordWrap = 50; // set word wrap
    $mail->Body = $sprava;
    $mail->IsHTML(true); // send as HTML
    $mail->Subject = $predmet;
    $mail->CharSet = "utf-8";
    if ($mail->Send())
        $odoslane = 1;
    else {
        if ($show_error)
            var_dump($mail->ErrorInfo);
        $odoslane = 0;
    }

    $akt_datcas = Date("Y-m-d H:i:s");

    $uloz_i = "INSERT INTO notifikacia (id, komu, predmet, text, datcas, odoslane) VALUES (NULL, '" . $komu . "', '" . $predmet . "', '" . $sprava . "', '" . $akt_datcas . "', '" . $odoslane . "')";
    $uloz_q = MySQL_Query($uloz_i);
}

function jazyky() {
    echo "<h2>Jazyky</h2>\n";
    echo "<form action=\"\" method=\"post\"><table>";
    echo "<tr><td>#</td><td>Slovenčina</td><td>Angličtina</td><td>Nemčina</td></tr>";
    $langs_s = "SELECT * FROM jazyk ORDER BY id ASC";
    $langs_q = MySQL_Query($langs_s);
    $i = 1;
    while ($langs = MySQL_Fetch_Array($langs_q)) {
        echo "<tr><td>" . $i . "</td><td>" . $langs['sk'] . "</td><td><input type=\"text\" name=\"en_" . $langs['id'] . "\" value=\"" . $langs['en'] . "\" style=\"width: 300px;\"></td><td><input type=\"text\" name=\"de_" . $langs['id'] . "\" value=\"" . $langs['de'] . "\" style=\"width: 300px;\"></td></tr>";
        $i++;
    }
    echo "<tr><td colspan=\"4\"><input type=\"hidden\" name=\"jazyky_uloz\" value=\"1\" /><input type=\"submit\" value=\"Uložiť\" /></td></tr>";
    echo "</table></form>";
}

function jazyky_sent() {
    $langs_s = "SELECT id FROM jazyk ORDER BY id ASC";
    $langs_q = MySQL_Query($langs_s);
    while ($langs = MySQL_Fetch_Array($langs_q)) {
        $en = "en_" . $langs['id'];
        $en_ok = Trim(HtmlSpecialChars($_POST[$en], ENT_QUOTES));
        $de = "de_" . $langs['id'];
        $de_ok = Trim(HtmlSpecialChars($_POST[$de], ENT_QUOTES));
        $zmen_u = "UPDATE jazyk SET en = '" . $en_ok . "', de = '" . $de_ok . "' WHERE id = '" . $langs['id'] . "' ";
        $zmen_q = MySQL_Query($zmen_u);
    }
    Header("Location: ?akc=13");
    exit();
}

function preklad($jid) {
    global $lang_id;
    if ($lang_id == 1)
        $lang = 'en';
    elseif ($lang_id == 2)
        $lang = 'de';
    else
        $lang = 'sk';
    $jid_ok = IntVal($jid);
    if ($jid_ok > 0) {
        $nac_s = "SELECT sk" . (($lang != 'sk') ? "," . $lang : "") . " FROM jazyk WHERE id = '" . $jid_ok . "' ";
        $nac_q = MySQL_Query($nac_s);
        $nac_n = MySQL_Num_Rows($nac_q);
        if ($nac_n == 1) {
            $nac = MySQL_Fetch_Array($nac_q);
            if (!Empty($nac[$lang]))
                $ret = $nac[$lang];
            else
                $ret = $nac['sk'];
        }
        else {
            $ret = 'not found';
        }
    } else {
        $ret = 'num error';
    }
    return $ret;
}

function change_lang($lang_ok) {
    global $user_id, $zedko;
    if ($zedko == 0)
        $zmen_u = "UPDATE user SET lang = '" . $lang_ok . "' WHERE id = '" . $user_id . "' ";
    else
        $zmen_u = "UPDATE z SET lang = '" . $lang_ok . "' WHERE id = '" . $user_id . "' ";
    $zmen_q = MySQL_Query($zmen_u);
    Header("Location: ?");
    exit();
}

function docs_zamx() {
    $ord = Array("nazov", "datum_pridania");
    $order = IntVal($_GET['order']);
    if (Empty($ord[$order])) {
        $order_ok = $ord[0];
        $order_x = 0;
    } else {
        $order_ok = $ord[$order];
        $order_x = $order;
    }

    $a = Array("ASC", "DESC");
    $a_obr = Array("asc", "desc");
    $asc = IntVal($_GET['asc']);
    if (Empty($a[$asc])) {
        $asc_ok = $a[0];
        $asc_x = 0;
    } else {
        $asc_ok = $a[$asc];
        $asc_x = $asc;
    }

    global $user_id;
    $len_s = "SELECT spolid FROM z WHERE id = '" . $user_id . "' ";
    $len_q = MySQL_Query($len_s);
    $len = MySQL_Fetch_Array($len_q);
    $spolid = $len['spolid'];

    $docs_s = "SELECT * FROM z_docs WHERE zid = '" . $user_id . "' ORDER BY " . $order_ok . " " . $asc_ok;
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    $i = 1;
    echo "<h2>" . preklad(3) . "</h2>\n";
    echo "<table>";
    echo "<tr><td>#</td><td><a href=\"?akc=14&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(66) . "</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=14&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_black\">" . preklad(67) . "</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td></tr>";
    while ($docs = MySQL_Fetch_Array($docs_q)) {
        echo "<tr><td>" . $i . "</td><td><a href=\"get_file_zamx.php?did=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td></tr>";
        $i++;
    }
    echo "</table>";
}

function vp() {
    bmb_vyber_spol();

    echo "<h2>Výplatné pásky</h2>\n";

    if (!Empty($_SESSION['bmb_spolid'])) {
        $spolid = $_SESSION['bmb_spolid'];

        $ord = Array("z.priezvisko", "stav.stav");
        $order = IntVal($_GET['order']);
        if (Empty($ord[$order])) {
            $order_ok = $ord[0];
            $order_x = 0;
        } else {
            $order_ok = $ord[$order];
            $order_x = $order;
        }

        $a = Array("ASC", "DESC");
        $a_obr = Array("asc", "desc");
        $asc = IntVal($_GET['asc']);
        if (Empty($a[$asc])) {
            $asc_ok = $a[0];
            $asc_x = 0;
        } else {
            $asc_ok = $a[$asc];
            $asc_x = $asc;
        }

        echo "<select onChange=\"jm(this)\" size=\"1\"><option value=\"0\"" . (($_SESSION['zobraz_zam'] == 0) ? " selected" : "") . ">všetci</option>";
        $stavy_s = "SELECT * FROM stav ORDER BY id ASC";
        $stavy_q = MySQL_Query($stavy_s);
        while ($stavy = MySQL_Fetch_Array($stavy_q)) {
            echo "<option value=\"" . $stavy['id'] . "\"" . (($_SESSION['zobraz_zam'] == $stavy['id']) ? " selected" : "") . ">" . $stavy['stav'] . "</option>";
        }
        echo "</select><br />\n";
        echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?bmb_zmen_stav=1&vp=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
        echo "<form action=\"\" method=\"post\" enctype=\"multipart/form-data\">\n";
        echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
        echo "<tr class=\"riadok_nadpis\"><td>#</td><td><a href=\"?akc=15&order=0&asc=" . (($order_x == 0 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Meno:</a>" . (($order_x == 0) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td><a href=\"?akc=15&order=1&asc=" . (($order_x == 1 && $asc_x == 0) ? "1" : "0" ) . "\" class=\"a_nadpis\">Stav:</a>" . (($order_x == 1) ? " <img src=\"images/order-" . $a_obr[$asc_x] . ".gif\" alt=\"\">" : "" ) . "</td><td>Počet VP:</td><td>Nová VP:</td></tr>\n";
        $akt_dat = Date("Y-m-d");
        $zam_s = "SELECT z.id,z.spolid,z.datum_pridania,z.datum_prichodu,z.datum_odchodu,z.meno,z.priezvisko,z.datum_zmeny,z.stavid,z.active,stav.stav FROM z,stav WHERE spolid = '" . $spolid . "' AND stav.id = z.stavid ";
        if ($_SESSION['zobraz_zam'] > 0)
            $zam_s .= "AND stavid = '" . $_SESSION['zobraz_zam'] . "' ";
        else
            $zam_s .= "";
        $zam_s .= "ORDER BY " . $order_ok . " " . $asc_ok;
        $zam_q = MySQL_Query($zam_s);
        $i = 1;
        while ($zam = MySQL_Fetch_Array($zam_q)) {
            echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td>" . $zam['priezvisko'] . " " . $zam['meno'] . "</td><td>" . $zam['stav'] . "</td><td align=\"center\">" . z_pocet_vp($zam['id']) . " - <a href=\"home.php?akc=15&akc2=2&zid=" . $zam['id'] . "\">zobraziť</a></td><td><input type=\"file\" size=\"80\" name=\"file_vp_" . $zam['id'] . "\"></td></tr>\n";
            $i++;
        }
        echo "</table>\n";
        echo "<input type=\"hidden\" name=\"vp_new\" value=\"1\"><input type=\"submit\" value=\"Uložiť VP\">\n";
        echo "</form>\n";
    }
}

function z_pocet_vp($zid) {
    $pocet_s = "SELECT id FROM vp WHERE zid = '" . $zid . "' AND active = 1";
    $pocet_q = MySQL_Query($pocet_s);
    $pocet_n = MySQL_Num_Rows($pocet_q);
    return $pocet_n;
}

function vp_new() {
    $spolid = $_SESSION['bmb_spolid'];
    $zam_s = "SELECT z.id,z.spolid,z.datum_pridania,z.datum_prichodu,z.datum_odchodu,z.meno,z.priezvisko,z.datum_zmeny,z.stavid,z.active,stav.stav FROM z,stav WHERE spolid = '" . $spolid . "' AND stav.id = z.stavid ORDER BY z.priezvisko ASC";
    $zam_q = MySQL_Query($zam_s);
    while ($zam = MySQL_Fetch_Array($zam_q)) {
        $zid = $zam['id'];
        $subor = "file_vp_" . $zid;
        if (!Empty($_FILES[$subor]['name'])) {
            $filename = Trim(HtmlSpecialChars($_FILES[$subor]['name']));
            $filename = Str_Replace(" ", "_", $filename);
            $ftp = "document_vp_" . $zid . "_" . MD5(MicroTime());
            $document = $_FILES[$subor]['tmp_name'];
            $type = $_FILES[$subor]['type'];
            @mkdir($document, 0777);
            @chmod($document, 0777);
            if (Move_Uploaded_File($document, DOCS_ADDRESS . $ftp)) {
                $akt_dat = Date("Y-m-d");
                $uloz_i = "INSERT INTO vp (id, nazov, ftp, type, datum_pridania, zid, active) VALUES (NULL, '" . $filename . "', '" . $ftp . "', '" . $type . "', '" . $akt_dat . "', '" . $zid . "', 1)";
                $uloz_q = MySQL_Query($uloz_i);
            }
        }
    }

    Header("Location: ?akc=15");
    exit();
}

function vp_zid($zid) {
    $zam_s = "SELECT meno,priezvisko,spolid FROM z WHERE id = '" . $zid . "' ";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);
    echo "<h2>Výplatné pásky</h2>\n";
    echo "zamestnanca: " . $zam['meno'] . " " . $zam['priezvisko'] . "\n<br /><br />\n";
    $docs_s = "SELECT * FROM vp WHERE zid = '" . $zid . "' AND active = 1 ORDER BY datum_pridania DESC";
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    if ($docs_n > 0) {
        $i = 1;
        echo "<table>";
        echo "<tr><td>#</td><td>Názov VP:</td><td>Dátum pridania:</td><td>&nbsp;</td></tr>";
        while ($docs = MySQL_Fetch_Array($docs_q)) {
            echo "<tr><td>" . $i . "</td><td><a href=\"get_file_vp.php?vpid=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td><td><a href=\"?akc=15&akc2=3&vpid=" . $docs['id'] . "\">vymazať</a></td></tr>";
            $i++;
        }
        echo "</table>";
    } else {
        echo "K tomuto zamestnancovi neboli pridané žiadne VP.";
    }
}

function vp_del($vpid) {
    $vp_s = "SELECT zid FROM vp WHERE id = '" . $vpid . "' ";
    $vp_q = MySQL_Query($vp_s);
    $vp = MySQL_Fetch_Array($vp_q);

    $zmaz_u = "UPDATE vp SET active = 0 WHERE id = '" . $vpid . "' ";
    $zmaz_q = MySQL_Query($zmaz_u);

    Header("Location: ?akc=15&akc2=2&zid=" . $vp['zid']);
    exit();
}

function vp_zamx() {
    global $user_id;
    $len_s = "SELECT spolid FROM z WHERE id = '" . $user_id . "' ";
    $len_q = MySQL_Query($len_s);
    $len = MySQL_Fetch_Array($len_q);
    $spolid = $len['spolid'];

    $zam_s = "SELECT meno,priezvisko,spolid FROM z WHERE id = '" . $user_id . "' ";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);
    echo "<h2>" . preklad(131) . "</h2>\n";
    $docs_s = "SELECT * FROM vp WHERE zid = '" . $user_id . "' AND active = 1 ORDER BY datum_pridania DESC";
    $docs_q = MySQL_Query($docs_s);
    $docs_n = MySQL_Num_Rows($docs_q);
    if ($docs_n > 0) {
        $i = 1;
        echo "<table>";
        echo "<tr><td>#</td><td>" . preklad(66) . "</td><td>" . preklad(67) . "</td></tr>";
        while ($docs = MySQL_Fetch_Array($docs_q)) {
            echo "<tr><td>" . $i . "</td><td><a href=\"get_file_vpx.php?vpid=" . $docs['id'] . "\">" . $docs['nazov'] . "</a> [" . docs_size($docs['ftp']) . "]</td><td>" . date_conv_to_view($docs['datum_pridania']) . "</td></tr>";
            $i++;
        }
        echo "</table>";
    }
}

function upravitManazera($zid) {
    if (isset($_POST['manazer']) && ($_POST['manazer'] == 1)) {
        $manazer = 1;
        $veduci = $_POST['manazer_oddelenia'];
        $patri_k = $_POST['veduci'];
    } else {
        $manazer = $_POST['manazer'];
        $veduci = 0;
        $patri_k = $_POST['veduci'];
    }
    $m_u = "UPDATE z SET manager='$manazer', veduci_oddelenia='$veduci', patri_k='$patri_k' WHERE id = '" . $zid . "' ";
    $m_q = MySQL_Query($m_u);
    Header("Location: home.php?akc=3&akc2=4&zid=" . $zid);
}

function jeSviatok($date) {
    $d = date('j', $date);
    $m = date('n', $date);
    $y = date('Y', $date);
    $sv_s = "SELECT id FROM sviatok WHERE den = '" . $d . "' AND mesiac='" . $m . "' AND rok='" . $y . "' ";
    $sv_q = MySQL_Query($sv_s);
    $sv = MySQL_Fetch_Array($sv_q);
    if (isset($sv['id'])) {
        return true;
    } else {
        return false;
    }
}

function typDochadzky($zid, $date) {
    $sv_s = "SELECT type FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    $sv_q = MySQL_Query($sv_s);
    $sv = MySQL_Fetch_Array($sv_q);
    if (isset($sv['type'])) {
        return $sv['type'];
    }
    return '0';
}

function vyplnenyCas($zid, $date, $term) {
    if ($term == 1)
        $sv_s = "SELECT planOd FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    if ($term == 2)
        $sv_s = "SELECT planDo FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    if ($term == 3)
        $sv_s = "SELECT realOd FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    if ($term == 4)
        $sv_s = "SELECT realDo FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    if ($term == 5)
        $sv_s = "SELECT splitOd FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    if ($term == 6)
        $sv_s = "SELECT splitDo FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND date='" . $date . "' ";
    $sv_q = MySQL_Query($sv_s);
    $sv = MySQL_Fetch_Array($sv_q);
    if (isset($sv['0'])) {
        return $sv['0'];
    }
    return '';
}

function zaokruhlenie($time, $type) {
    $result = array();
    /* if ($type == 'IN') { // prichod
      $od = explode(':', trim($time));
      if ($od[1]!='00') {
      $hod = ($od[0] + 1) % 24;
      if (strlen(trim($hod))==1) {
      $hod = '0'.$hod;
      }
      $result = array($hod,'00');
      } else {
      $result = $od;
      }
      } else if ($type == 'OUT') { // odchod
      $do = explode(':', trim($time));
      if ($do[1]!='00') {
      $hod = ($do[0]) % 24;
      if (strlen(trim($hod))==1) {
      $hod = '0'.$hod;
      }
      $result = array($hod,'00');
      } else {
      $result = $do;
      }
      } */
    $timee = explode(':', trim($time));
    $result = array($timee[0], $timee[1]);
    return $result;
}

function zistiPocetSekund($Od, $Do) {
    $od = zaokruhlenie(trim($Od), 'IN');
    $do = zaokruhlenie(trim($Do), 'OUT');
    if (trim($Od) == trim($Do))
        return 24 * 60 * 60;
    $pocSekOd = date("U", mktime($od[0], $od[1], 0, 1, 1, 2011));
    if (($od[0] > $do[0]) || (($od[0] == $do[0]) && ($od[1] > $do[1])))
        $pocSekDo = date("U", mktime($do[0], $do[1], 0, 1, 2, 2011));
    else
        $pocSekDo = date("U", mktime($do[0], $do[1], 0, 1, 1, 2011));
    return ($pocSekDo - $pocSekOd);
}

function zistiPocetSekundNoc($Od, $Do) {
    $od = zaokruhlenie(trim($Od), 'IN');
    $do = zaokruhlenie(trim($Do), 'OUT');
    if (trim($Od) == trim($Do))
        return (8 * 3600);
    $pocSekOd = date("U", mktime($od[0], $od[1], 0, 1, 1, 2011));
    if (($od[0] > $do[0]) || (($od[0] == $do[0]) && ($od[1] > $do[1]))) {
        $pocSekDo = date("U", mktime($do[0], $do[1], 0, 1, 2, 2011));
        $hod22 = date("U", mktime(22, 0, 0, 1, 1, 2011));
        $hod6 = date("U", mktime(6, 0, 0, 1, 2, 2011));
        //$hod6 = date("U", mktime(5, 0, 0, 1, 2, 2011));

        if (($pocSekOd <= $hod22) && ($pocSekDo >= $hod6)) {
            return (8 * 3600);
        } else if (($pocSekOd >= $hod22) && ($pocSekDo <= $hod6)) {
            return ($pocSekDo - $pocSekOd);
        } else if (($pocSekOd <= $hod22) && ($pocSekDo <= $hod6)) {
            return ($pocSekDo - $hod22);
        } else if (($pocSekOd >= $hod22) && ($pocSekDo >= $hod6)) {
            return ($hod6 - $pocSekOd);
        } else {
            return 0;
        }
    } else {
        $pocSekDo = date("U", mktime($do[0], $do[1], 0, 1, 1, 2011));
        $hod22 = date("U", mktime(22, 0, 0, 1, 1, 2011));
        $hod6 = date("U", mktime(6, 0, 0, 1, 1, 2011));
        //$hod6 = date("U", mktime(5, 0, 0, 1, 1, 2011));
        if (($pocSekOd <= $hod6) && ($pocSekDo >= $hod22)) {
            return ($hod6 - $pocSekOd + $pocSekDo - $hod22);
        } else if (($pocSekOd >= $hod6) && ($pocSekDo >= $hod22)) {
            return ($pocSekDo - $hod22);
        } else if (($pocSekOd <= $hod6) && ($pocSekDo <= $hod22)) {
            return ($hod6 - $pocSekOd);
        } else {
            return 0;
        }
    }
}

function vypocitatNadcas($zid, $date) {
    $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND type='P'";
    $nac_q = MySQL_Query($nac_s);
    $sum = 0;
    while ($nac = MySQL_Fetch_Array($nac_q)) {
        if ((date("Y", $nac['date']) == date("Y", $date))) {
            $plan = zistiPocetSekund($nac['planOd'], $nac['planDo']);
            $real = zistiPocetSekund($nac['realOd'], $nac['realDo']);
            $nadcas = $real - $plan;

            $sum += $nadcas;
        }
    }

    $nac_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND type='OT'";
    $nac_q = MySQL_Query($nac_s);
    $ot = 0;
    while ($nac = MySQL_Fetch_Array($nac_q)) {
        if ((date("Y", $nac['date']) == date("Y", $date))) {
            $ot++;
        }
    }

    $nacc_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $nacc_q = MySQL_Query($nacc_s);
    $nacc = MySQL_Fetch_Array($nacc_q);

    $dotacia = $nacc['fond'] / 5;

    $sum = $sum - ($ot * $dotacia * 3600);

    $delete_i = "DELETE FROM falknadcas WHERE zid='" . $zid . "' AND rok='" . (date("Y", $date)) . "'";
    $delete_q = MySQL_Query($delete_i);

    $uloz_i = "INSERT INTO falknadcas (id, zid, date, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $date . "','" . date("Y", $date) . "','" . $sum . "')";
    $uloz_q = MySQL_Query($uloz_i);
    $sum = $sum / 3600;
    $sum = (double) $sum;
    return ($sum);
}

function vypocitatStravu($zid, $date) {

    $danyTyzden = date("W", $date);
    $danyDen = $date;
    while (date("W", $danyDen) == $danyTyzden) {
        $danyDen -= (24 * 60 * 60);
    }
    $prvyDenVtyzdni = $danyDen + (24 * 60 * 60);


    if (date("n", $prvyDenVtyzdni) == date("n", $prvyDenVtyzdni + (6 * 24 * 3600))) {
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND date>='" . $prvyDenVtyzdni . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
        $nac_q = MySQL_Query($nac_s);
        $sum = 0;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$date)) && (date("Y",$nac['date'])==date("Y",$date))) {
            //$hodin = zistiPocetSekund($nac['realOd'], $nac['realDo']) / 3600;
            //$hodin = (int) $hodin;
            //if ($hodin>=8)
            $sum++;
            //}
        }
        $delete_i = "DELETE FROM falkstrava WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falkstrava (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);
    } else {
        $prvyDenVtyzdni2 = $prvyDenVtyzdni;
        $mam = false;
        for ($i = 1; $i < 7; $i++) {
            if ((date("n", $prvyDenVtyzdni) != date("n", $prvyDenVtyzdni + ($i * 24 * 3600))) && (!$mam)) {
                $prvyDenVtyzdni2 = $prvyDenVtyzdni + ($i * 24 * 3600);
                $mam = true;
            }
        }
        //prva cast tyzdna
        $sum = 0;
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND date>='" . $prvyDenVtyzdni . "' AND date<'" . ($prvyDenVtyzdni2) . "'";
        $nac_q = MySQL_Query($nac_s);
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            $sum++;
        }
        $delete_i = "DELETE FROM falkstrava WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falkstrava (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);

        //druha cast tyzdna
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND date>='" . $prvyDenVtyzdni2 . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
        $nac_q = MySQL_Query($nac_s);
        $sum = 0;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            $sum++;
        }
        $delete_i = "DELETE FROM falkstrava WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni2 . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falkstrava (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni2 . "','" . date("m", $prvyDenVtyzdni2) . "','" . date("Y", $prvyDenVtyzdni2) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);
    }

    return vypocitajFinalnuStravuKtyzdnu($zid, $prvyDenVtyzdni - (1 * 24 * 3600));
}

function vypocitatSviatok($zid, $date) {
    $danyTyzden = date("W", $date);
    $danyDen = $date;
    while (date("W", $danyDen) == $danyTyzden) {
        $danyDen -= (24 * 60 * 60);
    }
    $prvyDenVtyzdni = $danyDen + (24 * 60 * 60);


    if (date("n", $prvyDenVtyzdni) == date("n", $prvyDenVtyzdni + (6 * 24 * 3600))) {
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND ((type='P')OR(type='SPL')) AND sviatok!='0' AND date>='" . $prvyDenVtyzdni . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
        $nac_q = MySQL_Query($nac_s);
        $sum = 0;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$_POST['date'])) && (date("Y",$nac['date'])==date("Y",$_POST['date']))) {
            $sumTemp = zistiPocetSekund($nac['realOd'], $nac['realDo']);
            $sumTemp = $sumTemp - 1800;
            $sumTemp = $sumTemp / 3600;
            $sumTemp = (int) $sumTemp;
            $sumTemp = $sumTemp * 3600;
            $sum += $sumTemp;
            //}
        }
        $delete_i = "DELETE FROM falksviatok WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falksviatok (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);
    } else {
        $prvyDenVtyzdni2 = $prvyDenVtyzdni;
        $mam = false;
        for ($i = 1; $i < 7; $i++) {
            if ((date("n", $prvyDenVtyzdni) != date("n", $prvyDenVtyzdni + ($i * 24 * 3600))) && (!$mam)) {
                $prvyDenVtyzdni2 = $prvyDenVtyzdni + ($i * 24 * 3600);
                $mam = true;
            }
        }
        //prva cast tyzdna
        $sum = 0;
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND ((type='P')OR(type='SPL')) AND sviatok!='0' AND date>='" . $prvyDenVtyzdni . "' AND date<'" . ($prvyDenVtyzdni2) . "'";
        $nac_q = MySQL_Query($nac_s);
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$_POST['date'])) && (date("Y",$nac['date'])==date("Y",$_POST['date']))) {
            $sumTemp = zistiPocetSekund($nac['realOd'], $nac['realDo']);
            $sumTemp = $sumTemp - 1800;
            $sumTemp = $sumTemp / 3600;
            $sumTemp = (int) $sumTemp;
            $sumTemp = $sumTemp * 3600;
            $sum += $sumTemp;
            //}
        }
        $delete_i = "DELETE FROM falksviatok WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falksviatok (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);

        //druha cast tyzdna
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND ((type='P')OR(type='SPL')) AND sviatok!='0' AND date>='" . $prvyDenVtyzdni2 . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
        $nac_q = MySQL_Query($nac_s);
        $sum = 0;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$_POST['date'])) && (date("Y",$nac['date'])==date("Y",$_POST['date']))) {
            $sumTemp = zistiPocetSekund($nac['realOd'], $nac['realDo']);
            $sumTemp = $sumTemp - 1800;
            $sumTemp = $sumTemp / 3600;
            $sumTemp = (int) $sumTemp;
            $sumTemp = $sumTemp * 3600;
            $sum += $sumTemp;
            //}
        }
        $delete_i = "DELETE FROM falksviatok WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni2 . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falksviatok (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni2 . "','" . date("m", $prvyDenVtyzdni2) . "','" . date("Y", $prvyDenVtyzdni2) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);
    }
    
    return vypocitajFinalnySviatokKtyzdnu($zid, $prvyDenVtyzdni - (1 * 24 * 3600));
}

function vypocitatNocne($zid, $date) {
    $danyTyzden = date("W", $date);
    $danyDen = $date;
    while (date("W", $danyDen) == $danyTyzden) {
        $danyDen -= (24 * 60 * 60);
    }
    $prvyDenVtyzdni = $danyDen + (24 * 60 * 60);


    if (date("n", $prvyDenVtyzdni) == date("n", $prvyDenVtyzdni + (6 * 24 * 3600))) {
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND ((type='P')OR(type='SPL')) AND date>='" . $prvyDenVtyzdni . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
        $nac_q = MySQL_Query($nac_s);
        $sum = 0;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$_POST['date'])) && (date("Y",$nac['date'])==date("Y",$_POST['date']))) {
            $sumTemp = zistiPocetSekundNoc($nac['realOd'], $nac['realDo']);
            //$sumTemp = $sumTemp - 1800;
            $sumTemp = $sumTemp / 3600;
            $sumTemp = (int) $sumTemp;
            $sumTemp = $sumTemp * 3600;
            $sum += $sumTemp;
            //}
        }
        $delete_i = "DELETE FROM falknoc WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falknoc (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);
    } else {
        $prvyDenVtyzdni2 = $prvyDenVtyzdni;
        $mam = false;
        for ($i = 1; $i < 7; $i++) {
            if ((date("n", $prvyDenVtyzdni) != date("n", $prvyDenVtyzdni + ($i * 24 * 3600))) && (!$mam)) {
                $prvyDenVtyzdni2 = $prvyDenVtyzdni + ($i * 24 * 3600);
                $mam = true;
            }
        }
        //prva cast tyzdna
        $sum = 0;
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND ((type='P')OR(type='SPL')) AND date>='" . $prvyDenVtyzdni . "' AND date<'" . ($prvyDenVtyzdni2) . "'";
        $nac_q = MySQL_Query($nac_s);
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$_POST['date'])) && (date("Y",$nac['date'])==date("Y",$_POST['date']))) {
            $sumTemp = zistiPocetSekundNoc($nac['realOd'], $nac['realDo']);
            //$sumTemp = $sumTemp - 1800;
            $sumTemp = $sumTemp / 3600;
            $sumTemp = (int) $sumTemp;
            $sumTemp = $sumTemp * 3600;
            $sum += $sumTemp;
            //}
        }
        $delete_i = "DELETE FROM falknoc WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falknoc (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);

        //druha cast tyzdna
        $nac_s = "SELECT * FROM dochadzkazamfalk WHERE realOd!='' AND realDo!='' AND zid = '" . $zid . "' AND ((type='P')OR(type='SPL')) AND date>='" . $prvyDenVtyzdni2 . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
        $nac_q = MySQL_Query($nac_s);
        $sum = 0;
        while ($nac = MySQL_Fetch_Array($nac_q)) {
            //if ((date("m",$nac['date'])==date("m",$_POST['date'])) && (date("Y",$nac['date'])==date("Y",$_POST['date']))) {
            $sumTemp = zistiPocetSekundNoc($nac['realOd'], $nac['realDo']);
            //$sumTemp = $sumTemp - 1800;
            $sumTemp = $sumTemp / 3600;
            $sumTemp = (int) $sumTemp;
            $sumTemp = $sumTemp * 3600;
            $sum += $sumTemp;
            //}
        }
        $delete_i = "DELETE FROM falknoc WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni2 . "'";
        $delete_q = MySQL_Query($delete_i);

        $uloz_i = "INSERT INTO falknoc (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni2 . "','" . date("m", $prvyDenVtyzdni2) . "','" . date("Y", $prvyDenVtyzdni2) . "','" . $sum . "')";
        $uloz_q = MySQL_Query($uloz_i);
    }

    return vypocitajFinalnyNocnyKtyzdnu($zid, $prvyDenVtyzdni - (1 * 24 * 3600));
}

function vypocitatMOD($zid, $date) {
    $danyTyzden = date("W", $date);
    $danyDen = $date;
    while (date("W", $danyDen) == $danyTyzden) {
        $danyDen -= (24 * 60 * 60);
    }
    $prvyDenVtyzdni = $danyDen + (24 * 60 * 60);

    $nac_s = "SELECT * FROM dochadzkazamfalk WHERE type='MOD' AND zid = '" . $zid . "' AND date>='" . $prvyDenVtyzdni . "' AND date<='" . ($prvyDenVtyzdni + (6 * 24 * 3600)) . "'";
    $nac_q = MySQL_Query($nac_s);
    $sum = 0;
    while ($nac = MySQL_Fetch_Array($nac_q)) {
        $sum++;
    }
    $sum = $sum / 2;
    $delete_i = "DELETE FROM falkmod WHERE zid='" . $zid . "' AND date='" . $prvyDenVtyzdni . "'";
    $delete_q = MySQL_Query($delete_i);

    $uloz_i = "INSERT INTO falkmod (id, zid, date, mesiac, rok, kolko) VALUES (NULL, '" . $zid . "', '" . $prvyDenVtyzdni . "','" . date("m", $prvyDenVtyzdni) . "','" . date("Y", $prvyDenVtyzdni) . "','" . $sum . "')";
    $uloz_q = MySQL_Query($uloz_i);

    return vypocitajFinalnyModKtyzdnu($zid, $prvyDenVtyzdni - (1 * 24 * 3600));
}

function vlozPlan($zid, $date0, $week, $day, $value = 'P') {
    $date = $date0 + ($week - 1) * (7 * 24 * 60 * 60) + ($day * 24 * 60 * 60);
    if (typDochadzky($zid, $date) == '0') {
        $d = date('j', $date);
        $m = date('n', $date);
        $y = date('Y', $date);
        $sv_s = "SELECT id FROM sviatok WHERE den = '" . $d . "' AND mesiac='" . $m . "' AND rok='" . $y . "' ";
        $sv_q = MySQL_Query($sv_s);
        $sv = MySQL_Fetch_Array($sv_q);
        if (isset($sv['id'])) {
            $sviatok = $sv['id'];
        } else {
            $sviatok = 0;
        }
        $uloz_i = "INSERT INTO dochadzkazamfalk (id, zid, date, type, sviatok) VALUES (NULL, '" . $zid . "', '" . $date . "', '" . $value . "', '" . $sviatok . "')";
        $uloz_q = MySQL_Query($uloz_i);
    }
}

function novyPlan($zid, $date) {
    return (typDochadzky($zid, $date));
}

function filterDiacritics($input) {
    $input = str_replace('á', 'a', $input);
    $input = str_replace('é', 'e', $input);
    $input = str_replace('í', 'i', $input);
    $input = str_replace('ó', 'o', $input);
    $input = str_replace('ô', 'o', $input);
    $input = str_replace('ú', 'u', $input);
    $input = str_replace('ď', 'd', $input);
    $input = str_replace('ť', 't', $input);
    $input = str_replace('ň', 'n', $input);
    $input = str_replace('ľ', 'l', $input);
    $input = str_replace('ĺ', 'l', $input);
    $input = str_replace('ŕ', 'r', $input);
    $input = str_replace('č', 'c', $input);
    $input = str_replace('š', 's', $input);
    $input = str_replace('ž', 'z', $input);
    $input = str_replace('ý', 'y', $input);

    $input = str_replace('Á', 'A', $input);
    $input = str_replace('É', 'E', $input);
    $input = str_replace('Í', 'I', $input);
    $input = str_replace('Ó', 'O', $input);
    $input = str_replace('Ú', 'U', $input);
    $input = str_replace('Ď', 'D', $input);
    $input = str_replace('Ť', 'T', $input);
    $input = str_replace('Ň', 'N', $input);
    $input = str_replace('Ľ', 'L', $input);
    $input = str_replace('Ĺ', 'L', $input);
    $input = str_replace('Ŕ', 'R', $input);
    $input = str_replace('Č', 'C', $input);
    $input = str_replace('Š', 'S', $input);
    $input = str_replace('Ž', 'Z', $input);
    $input = str_replace('Ý', 'Y', $input);

    $input = str_replace(' ', '_', $input);

    return $input;
}

function toLower($input) {
    $input = str_replace('A', 'a', $input);
    $input = str_replace('Á', 'á', $input);
    $input = str_replace('B', 'b', $input);
    $input = str_replace('C', 'c', $input);
    $input = str_replace('Č', 'č', $input);
    $input = str_replace('D', 'd', $input);
    $input = str_replace('Ď', 'ď', $input);
    $input = str_replace('E', 'e', $input);
    $input = str_replace('É', 'é', $input);
    $input = str_replace('F', 'f', $input);
    $input = str_replace('G', 'g', $input);
    $input = str_replace('H', 'h', $input);
    $input = str_replace('I', 'i', $input);
    $input = str_replace('Í', 'í', $input);
    $input = str_replace('J', 'j', $input);
    $input = str_replace('K', 'k', $input);
    $input = str_replace('L', 'l', $input);
    $input = str_replace('Ľ', 'ľ', $input);
    $input = str_replace('Ĺ', 'ĺ', $input);
    $input = str_replace('M', 'm', $input);
    $input = str_replace('N', 'n', $input);
    $input = str_replace('Ň', 'ň', $input);
    $input = str_replace('O', 'o', $input);
    $input = str_replace('Ó', 'ó', $input);
    $input = str_replace('P', 'p', $input);
    $input = str_replace('Q', 'q', $input);
    $input = str_replace('R', 'r', $input);
    $input = str_replace('Ŕ', 'ŕ', $input);
    $input = str_replace('S', 's', $input);
    $input = str_replace('Š', 'š', $input);
    $input = str_replace('T', 't', $input);
    $input = str_replace('Ť', 'ť', $input);
    $input = str_replace('U', 'u', $input);
    $input = str_replace('Ú', 'ú', $input);
    $input = str_replace('V', 'v', $input);
    $input = str_replace('X', 'x', $input);
    $input = str_replace('Y', 'y', $input);
    $input = str_replace('Ý', 'ý', $input);
    $input = str_replace('Z', 'z', $input);
    $input = str_replace('Ž', 'ž', $input);
    return $input;
}

function zoznam_oddeleni() {
    echo "<h2>" . preklad(153) . "</h2>\n";
    echo "<a href=\"home.php?akc=78&akc2=1\">* " . preklad(154) . "</a><br />\n";
    echo "<script language=\"JavaScript\" type=\"text/JavaScript\">\n<!--\nvar lv = false;\nfunction jm(selObj){\n  if (lv) return;\n  if(selObj.options[selObj.selectedIndex].value==\"none\")return;\n  lv = true;\n  eval(\"parent.location='home.php?b=1&zobraz=\"+selObj.options[selObj.selectedIndex].value+\"'\");\n}\n//-->\n</script>\n";
    echo "<table class=\"tabulka\" cellspacing=\"1\" cellpadding=\"4\">\n";
    echo "<tr class=\"riadok_nadpis\"><td>#</td><td>" . preklad(155) . "</td><td>" . preklad(139) . ":</td></tr>\n";
    $zam_s = "SELECT * FROM oddelenie ORDER BY nazov";
    $zam_q = MySQL_Query($zam_s);
    $i = 1;
    while ($zam = MySQL_Fetch_Array($zam_q)) {
        echo "<tr style=\"background: " . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . ";\" onMouseOver=\"this.style.background='#c0c0c0';\" onMouseOut=\"this.style.background='" . (($i % 2 == 1) ? "#ffffff" : "#f0f0f0") . "';\"><td>" . $i . "</td><td>" . $zam['nazov'] . "</td>";
        echo "<td>";
        $veduci_s = "SELECT * FROM z WHERE veduci_oddelenia='" . $zam['id'] . "'";
        $veduci_q = MySQL_Query($veduci_s);
        $str = '';
        while ($veduci = MySQL_Fetch_Array($veduci_q)) {
            $str .= $veduci['meno'] . ' ' . $veduci['priezvisko'] . ', ';
        }
        echo substr($str, 0, strlen($str) - 2);
        echo "</td></tr>\n";
        $i++;
    }
    echo "</table>";
}

function pridaj_oddelenie() {
    echo '<h2>Pridať oddelenie</h2>';
    echo '<form action="home.php?akc=78" method="post">';
    echo '<table>';
    echo '<tr>';
    echo '<td>Meno oddelenia</td>';
    echo '<td><input name="meno_oddelenia" type="text" /></td>';
    echo '</tr>';
    echo '<table>';
    echo '<tr>';
    echo '<td><input name="pridat_oddelenie" type="submit" value="Pridať" /></td>';
    echo '<td></td>';
    echo '</tr>';
    echo '</table>';
    echo '</form>';
}

function pridatOddelenie($name) {
    $uloz_i = "INSERT INTO oddelenie (id, nazov) VALUES (NULL, '" . $name . "')";
    $uloz_q = MySQL_Query($uloz_i);
}

function zafarbiSviatok($date, $color = 'yellow') {
    if (jeSviatok($date))
        echo 'background: ' . $color;
}

function vypocitajFinalnyNadcas($zid, $year) {
    $zam_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);

    $fond = $zam['fond'];

    $s_s = "SELECT SUM(kolko) AS kolko FROM falknadcas WHERE zid = '" . $zid . "' AND rok='" . $year . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND type='OT'";
    $d_q = MySQL_Query($d_s);
    $pot = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if (date("Y", $d['date']) == $year) {
            $pot++;
        }
    }
    $ot = $pot * $fond / 5;

    return ($s['kolko'] - $ot);
}

function vypocitajFinalnyNadcasKtyzdnu($zid, $endOfWeek) {
    $zam_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);

    $fond = $zam['fond'];

    $s_s = "SELECT SUM(kolko) AS kolko FROM falknadcas WHERE zid = '" . $zid . "' AND date<='" . $endOfWeek . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='OT' OR type='OPT')";
    $d_q = MySQL_Query($d_s);
    $pot = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if ($d['date'] <= $endOfWeek) {
            $pot++;
        }
    }
    $ot = $pot * $fond / 5;
    
    return (round($s['kolko'],2) - $ot);
}

function vypocitajFinalnyNadcasKmesiacu($zid, $month, $year) {
    $zam_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);

    $fond = $zam['fond'];

    $s_s = "SELECT SUM(kolko) AS kolko FROM falknadcas WHERE zid = '" . $zid . "' AND mesiac<='" . $month . "' AND rok<='" . $year . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='OT' OR type='OPT')";
    $d_q = MySQL_Query($d_s);
    $pot = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if ((date("Y", $d['date']) <= $year) && (date("n", $d['date']) <= $month)) {
            $pot++;
        }
    }
    $ot = $pot * $fond / 5;

    return ($s['kolko'] - $ot);
}

function vypocitajFinalnyMod($zid, $year) {
    $zam_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);

    $fond = $zam['fond'];

    $s_s = "SELECT SUM(kolko) AS kolko FROM falkmod WHERE zid = '" . $zid . "' AND rok='" . $year . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='OT' OR type='OTP')";
    $d_q = MySQL_Query($d_s);
    $pot = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if (date("Y", $d['date']) == $year) {
            if ($d['type'] == 'OT')
                $pot++;
            if ($d['type'] == 'OTP')
                $pot += 0.5;
        }
    }
    $ot = $pot;

    return ($s['kolko'] - $ot);
}

function vypocitajFinalnyModKtyzdnu($zid, $endOfWeek) {
    $zam_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);

    $fond = $zam['fond'];

    $s_s = "SELECT SUM(kolko) AS kolko FROM falkmod WHERE zid = '" . $zid . "' AND date<='" . $endOfWeek . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='OT' OR type='OTP')";
    $d_q = MySQL_Query($d_s);
    $pot = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if ($d['date'] <= $endOfWeek) {
            if ($d['type'] == 'OT')
                $pot++;
            if ($d['type'] == 'OTP')
                $pot += 0.5;
        }
    }
    //echo '<br/>';
    $ot = $pot;

    return ($s['kolko'] - $ot);
}

function vypocitajFinalnyModKMesiacu($zid, $month, $year) {
    $zam_s = "SELECT * FROM z WHERE id = '" . $zid . "'";
    $zam_q = MySQL_Query($zam_s);
    $zam = MySQL_Fetch_Array($zam_q);

    $fond = $zam['fond'];

    $s_s = "SELECT SUM(kolko) AS kolko FROM falkmod WHERE zid = '" . $zid . "' AND (((rok='" . $year . "') AND (mesiac<='" . $month . "')) OR (rok<'".$year."'))";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='OT' OR type='OTP')";
    $d_q = MySQL_Query($d_s);
    $pot = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if (((date("Y", $d['date']) == $year) && (date("n", $d['date']) <= $month)) || (date("Y", $d['date']) < $year)) {
            if ($d['type'] == 'OT')
                $pot++;
            if ($d['type'] == 'OTP')
                $pot += 0.5;
        }
    }
    $ot = $pot;

    return ($s['kolko'] - $ot);
}

function zablokovany($odchod, $prichod, $date) {
    if (($odchod[0] == '0000') && ($odchod[1] == '00') && ($odchod[2] == '00')) {
        //return '';
    }
    if (($prichod[0] == '0000') && ($prichod[1] == '00') && ($prichod[2] == '00')) {
        //return '';
    }
    if ((($odchod[0] != '0000') || ($odchod[1] != '00') || ($odchod[2] != '00')) && ((date("U", mktime(0, 0, 0, $odchod[1], $odchod[2], $odchod[0]))) < $date) || ((($prichod[0] != '0000') || ($prichod[1] != '00') || ($prichod[2] != '00')) && (date("U", mktime(0, 0, 0, $prichod[1], $prichod[2], $prichod[0]))) > $date))
        echo ' disabled ';
    else
        return '';
}

function zablokovanyDen($mesiac, $date) {
    //return false;
    $dochMesiac = date("n", $date);
    $desiatyDen = date("U", mktime(0, 0, 0, $dochMesiac + 1, 10, date("Y")));
    $block = false;
    if (date("U") > $desiatyDen) {
        $block = true;
    }

    if (($mesiac != $dochMesiac) && ($block)) {
        return true;
    }
    return false;
}

function block($prvy, $posledny, $desiatyDen, $dnesnyDen) {

    if (($dnesnyDen > $desiatyDen) && (date("n", $posledny) == date("n", $prvy)))
        return true;
    if ((($dnesnyDen - $posledny) / (30 * 24 * 3600)) >= 2)
        return true;
    /* if (((date("n", $dnesnyDen)-date("n", $posledny))>=2) && (date("Y", $desiatyDen)==date("Y", $dnesnyDen)))
      return true;
      if (((date("n", $dnesnyDen)-date("n", $posledny))<=-10) && (date("Y", $desiatyDen)<=date("Y", $dnesnyDen)))
      return true;
      //if ((date('Y', $desiatyDen)) >= (date('Y', $dnesnyDen)))
      // return true;
      if ((date('Y', $desiatyDen)) >= (date('Y', $dnesnyDen))) {
      echo $rozdiel = date("n", $dnesnyDen) - $dochMesiac2;
      if ((($rozdiel >= 2)) || (($dnesnyDen > $desiatyDen) && ($dochMesiac == $dochMesiac2))) {
      //echo 'vliezlo do podmienky';
      return true;
      }
      } else {
      return true;
      }
     */
    return false;
}

function upravPoradie($zam, $poradie, $mode, $veduci_oddelenia) {
    if ($mode == '-') {
        $temp = $poradie - 1;
    } else if ($mode == '+') {
        $temp = $poradie + 1;
    }

    $uloz_i = "UPDATE z SET poradie=" . $poradie . " WHERE patri_k=" . $veduci_oddelenia . " AND poradie=" . $temp;
    $uloz_q = MySQL_Query($uloz_i);

    $uloz_i = "UPDATE z SET poradie=" . $temp . " WHERE id=" . $zam;
    $uloz_q = MySQL_Query($uloz_i);
}

function vypocitajFinalnyNocnyKtyzdnu($zid, $endOfWeek) {
    $mesiac = date("n", $endOfWeek);
    $rok = date("Y", $endOfWeek);
    $s_s = "SELECT SUM(kolko) AS kolko FROM falknoc WHERE zid = '" . $zid . "' AND mesiac='" . $mesiac . "' AND rok='" . $rok . "' AND date<='" . $endOfWeek . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $sum = $s['kolko'] / 3600;
    $sum = (int) $sum;
    return ($sum);
}

function vypocitajFinalnySviatokKtyzdnu($zid, $endOfWeek) {
    $mesiac = date("n", $endOfWeek);
    $rok = date("Y", $endOfWeek);
    $s_s = "SELECT SUM(kolko) AS kolko FROM falksviatok WHERE zid = '" . $zid . "' AND mesiac='" . $mesiac . "' AND rok='" . $rok . "' AND date<='" . $endOfWeek . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    $sum = $s['kolko'] / 3600;
    $sum = (int) $sum;
    return ($sum);
}

function vypocitajFinalnuStravuKtyzdnu($zid, $endOfWeek) {
    $mesiac = date("n", $endOfWeek);
    $rok = date("Y", $endOfWeek);
    $s_s = "SELECT SUM(kolko) AS kolko FROM falkstrava WHERE zid = '" . $zid . "' AND mesiac='" . $mesiac . "' AND rok='" . $rok . "' AND date<='" . $endOfWeek . "'";
    $s_q = MySQL_Query($s_s);
    $s = MySQL_Fetch_Array($s_q);

    return $s['kolko'];
}

function pocetOdpracovanychHodin($zid, $month, $year) {
    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='P' OR type='SPL') AND realOd!='' AND realDo!=''";
    $d_q = MySQL_Query($d_s);
    $sum = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        if ((date("Y", $d['date']) == $year) && (date("n", $d['date']) == $month)) {
            $odrobene = zistiPocetSekund($d['realOd'], $d['realDo']);
            $n = $odrobene / 1800;
            $n = (int) $n;
            $n = $n / 2;
            $sum += $n;
        }
    }
    return ($sum);
}

function pocetOdpracovanychHodinKtyzdnu($zid, $endOfWeek) {
    $d_s = "SELECT * FROM dochadzkazamfalk WHERE zid = '" . $zid . "' AND (type='P' OR type='SPL') AND realOd!='' AND realDo!='' AND date<='" . $endOfWeek . "'";
    $d_q = MySQL_Query($d_s);
    $sum = 0;
    while ($d = MySQL_Fetch_Array($d_q)) {
        $odrobene = zistiPocetSekund($d['realOd'], $d['realDo']);
        $n = $odrobene / 1800;
        $n = (int) $n;
        $n = $n / 2;
        $sum += $n;
    }
    return ($sum);
}

?>